FAQ Database Discussion Community


PHP convert Array with SimpleXMLElement Object to XML

php,arrays,xml,simplexml
I have an array with some SimpleXMLElement Objects inside and now i need to get a well formed XML for Ajax interaction, how can i do? This is the array: Array ( [0] => SimpleXMLElement Object ( [count] => 2 [id] => 20 [user_id] => 2 [title] => Polo RL...

How to get the role nodes

php,xml,simplexml
How can I get the role node of the "Blog-Autor"-Role and "Kommentar-Manager"-Role? Or is there a way to do it more dynamicly with the role nodes? My XML: <roles> <role role="Administrator"> <role role="Account Manager"> <role role="Blog-Autor"/> <role role="Kommentar-Manager"/> </role> </role> </roles> And my php-code with which Im going through the...

XML: php only parsing first in a series of children

php,xml,parsing,simplexml
I have an XML string that I'm trying to extract the names of the children tags. Each child tag is self-closing. I'm trying to use SimpleXMLElement $xml_str = '1<?xml version="1.0" encoding="UTF-8"?><parent><personal_data><child1 attr="sth /><child2 attr=sth2/></personal_data><personal_data><child1 attr="sth /><child2 attr=sth2/></personal_data</parent>'; $sxe = new SimpleXMLElement($xml); //get the children from the parent $sxe = $sxe->children();...

Using php's SimpleXMLItterator to print sub elements in order

php,xml,simplexml
I am dealing with the following XML: <Paragraph>This is a test. This is a test. <Italic>This is an italicized test</Italic> This is more tests </Paragraph> I'm trying to pull in the XML, modify it as a text string or HTML code, and spit it back out. I'm running into the...

How to parse value `@attribute` from a SimpleXMLObject in PHP

php,xml,parsing,simplexml
I am trying to parse the starkoverflow.com/feeds/tag/{$tagName}. This is my code: <?php $xml = file_get_contents("http://stackoverflow.com/feeds/tag/php"); $simpleXml = simplexml_load_string($xml); $attr = $simpleXml->entry->category->@attributes; ?> When I execute the above code it gives me a error, Parse error: syntax error, unexpected '@', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in...

PHP SimpleXML Getting a child node attribute based on a node attribute

php,xml,xpath,simplexml
I'm trying to loop through an XML file formatted like so: <colors> ... </colors> <sets> <settype type="hr" paletteid="2" mand_m_0="0" mand_f_0="0" mand_m_1="0" mand_f_1="0"> <set id="175" gender="M" club="0" colorable="0" selectable="0" preselectable="0"> <part id="996" type="hr" colorable="0" index="0" colorindex="0"/> </set> ... </settype> <settype type="ch" paletteid="3" mand_m_0="1" mand_f_0="1" mand_m_1="0" mand_f_1="1"> <set id="680" gender="F" club="0" colorable="1"...

How to get a specific value in SimpleXML by specified attributes?

php,simplexml
The structure of my XML file is: <?xml version="1.0" encoding="UTF-8"?> .... .. . <usernames> <user id="harrypotter"> <topicid id="1"> <commentid>1</commentid> </topicid> <topicid id="2"> <commentid>2</commentid> </topicid> <topicid id="3"> <commentid>3</commentid> </topicid> <topicid id="4"> <commentid>4</commentid> </topicid> <topicid id="5"> <commentid>5</commentid> </topicid> <topicid...

PHP SimpleXMLElement: How to add dynamic child with ampersand escaping

php,xml,simplexml,xml-generation
I'm using the following code to add dynamic child to an xml node <?php $recordXML = new SimpleXMLElement("<Record></Record>"); $rowXML = $recordXML->addChild('row'); foreach ($array as $column => $column_value) { $rowXML->addChild($column,$column_value ); } This code gives "unterminated entity reference" warning! when there is an ampresand & in any of the $column_value, I...

PHP SimpleXMLElement - Can't Retrieve 'Description' Element From Feed

php,simplexml
I don't have much idea of crawling XML documents. Might be a little mistake. Feed URL: http://www.simplifyingthemarket.com/feed/ Code:- $url = 'http://www.simplifyingthemarket.com/feed/'; $XmlObject = new SimpleXmlElement( file_get_contents($url) ); print_r($XmlObject->channel[0]->item[0]->description[0]); Output:- SimpleXMLElement Object ( ) Required Output:- <a href="http://www.simplifyingthemarket.com/wp-content/uploads/2015/04/Where-Should-I-Retire.jpg"><img class="alignnone wp-image-30608"...

Simplexml get path from variable

variables,path,simplexml
Is there a way to pass the path to a simplexml node as a variable? This is what I tried: //set the path to the node in a variable $comp = 'component->structuredBody->component'; echo count($xml->component->structuredBody->component); //=== 13 echo count($xml->$comp); //===0 echo count($xml->{$comp});//===0 ...

getting summarized nodes instead of separate nested nodes

php,xml,simplexml
I've a third party xml file like this. It's a movie app that organizes which scene is shot on which shooting day. <schedule> <DayBreak> <AutoText>true</AutoText> <Text></Text> </DayBreak> <Scene> 81 </Scene> <DayBreak> <AutoText>false</AutoText> <Text>myday</Text> </DayBreak> <Scene> 82 </Scene> <Scene> 85 </Scene> <schedule /> As you see, there is a new day,...

php simplexml grouping objects

php,xml,group-by,simplexml
Before I start I would like to say I am a noob at reading XML into PHP but I have so far managed to load XML and display the data onto a PHP page. My next test is to group items. Here is an XML snippet: <MailboxDatabases> <MailboxDatabase> <DatabaseName>DB01</DatabaseName> <Status>Healthy</Status>...

Construct SimpleXMLelement with xml header only in PHP

php,xml,simplexml
I have following code $xml_start = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><xml></xml>'); and I need to get rid of the tags. Any tag name works, but when I remove the tags I get an exception 'String could not be parsed as XML'. I can't figure out how to initialize the SimpleXMLelement with...

How to get array value from name instead index?

php,xml,simplexml
I have this following xml: <result> <rowset name="jumpClones" key="jumpCloneID" columns="jumpCloneID,typeID,locationID,cloneName"/> <rowset name="jumpCloneImplants" key="jumpCloneID" columns="jumpCloneID,typeID,typeName"/> <rowset name="implants" key="typeID" columns="typeID,typeName"> <row typeID="9899" typeName="Ocular Filter - Basic"/> <row typeID="9941" typeName="Memory Augmentation - Basic"/> <row typeID="9942" typeName="Neural Boost - Basic"/> <row typeID="9943" typeName="Cybernetic...

Fixing “Warning: Illegal string offset” — (but without losing content)

php,web-services,codeigniter,simplexml
I have searched for solution for this problem but none fix my problem. The answers suggest that I use isset to check the array before working on it. But I will explain how it doesnt do it for me later. Pre-req: I've got a huge XML file from a...

Convert XML to Object in PHP and again convert that Object to XML? [duplicate]

php,xml,simplexml,domdocument
This question is an exact duplicate of: How to convert XML to OCI-Lob Object? 1 answer Lets say I have a XML as below - $xml = '<?xml version="1.0"?> <step number="9"> <s_name>test</s_name> <b_sel>12345</b_sel> <b_ind>7</b_ind> </step>'; I want this to be converted to object, but when I perform below steps,...

Error when parsing the webservice response in PHP

php,web-services,simplexml,soap-client
I am at the learning stage of PHP. I have tried to invoke a sample webservice from a single PHP script. I started with StockQuote service. Below is the script I have written. <?php echo "Stock Quote service check"; require_once 'nusoap.php'; $wsdl="http://www.webservicex.net/stockquote.asmx?wsdl"; $client=new SoapClient($wsdl); $param=array('symbol'=>'GOOG'); $response = $client->__soapCall('GetQuote', array($params)); $quotes...

Using SimpleXMLElement::registerXPathNamespace - test case attached [duplicate]

php,xml-parsing,simplexml
This question already has an answer here: Simplexml get attributes with a namespace 1 answer I have prepared a simple test case for my question - please run it on a command line with php -f test.php and you will see my problem. I am trying to draw a...

How to str_replace Google News RSS for Facebook Share?

regex,rss,preg-match,simplexml,str-replace
Hi I'm using simpleXML to display a news.google.com feed. The displayed entries link to the original article in this way: http://news.google.com/news/url?sa=t&fd=R&ct2=us&usg=AFQjCNEcqhcp4AfUzgxc2l1gumydaxQ-KQ&clid=c3a7d30bb8a4878e06b80cf16b898331&cid=52778832126843&ei=keFLVfiHGvDVmQL5_4GgBg&url=http://WEBSITEWITHNEWS.COM/ARTICLEURLHERE I need the entries to link to this instead: http://WEBSITEWITHNEWS.COM/ARTICLEURLHERE The reason is that Facebook Sharer cannot interpret the following link:...

SimpleXML namespaced attributes and value is empty?

php,xml,simplexml
I have the following type of XML structure: <catalog xmlns="http://www.namespace.com"> <product product-id="test-product"> <page-attributes> <page-title xml:lang="en">test</page-title> <page-title xml:lang="de">test2</page-title> </page-attributes> </product> </catalog> I used the following to fetch the product and it's page-title elements: $xml->registerXPathNamespace('ns', $xml->getNamespaces()[""]); $xpath = '//ns:product[@product-id="test-product"]'; $product =...

Referencing a field by its ID instead of expanding it

java,simplexml,simple-framework
I am new to the Simple framework for XML (Java) and ran into a problem serializing specific class constructs. I have two classes: @Root(name="static") class StaticData { @Attribute private String id; @Attribute private String value; ... } and @Root(name="listdata") class ListData { // Problem field @Attribute private StaticData ref; @Element...

count xml elements/nodes using SimpleXML

php,xml,simplexml
this could be duplicate, but I found nothing useful so far. I'm trying to count nodes/childs of XML file using simplexml. I've tried this. $xml = simplexml_load_file("./file.xml"); echo count($xml->rss->channel->item); and echo count($xml->item); but just outputting 0. here is snapshot of XML <?xml version="1.0"?> <rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:g="http://base.google.com/ns/1.0" version="2.0"> <channel> <item>...

SimpleXMLElement return weird XML structure

php,sql,xml,simplexml
I'm struggling with SimpleXMLElement for quite some time and I can't figure out how to output a well formatted XML document. With a SQL query, I retrieve some data as XML format. select S_MODELE, S_ID from stock FOR XML RAW ('Product'), ROOT ('Products'), ELEMENTS" In php, I have a variable...

Simple XML @ElementMap unable to satisfy key attribute

java,xml,simplexml
I'm trying to deserialise with Simple XML 2.6.2 using the @ElementMap annotation to build a map containing an element's attribute as the key and the element itself as the value. The XML looks like this: <ProcessConfiguration id="4020"> <EquipmentConfigurations> <EquipmentConfiguration id="5020"> <address>foo</address> </EquipmentConfiguration> </EquipmentConfigurations> </ProcessConfiguration> The annotated classes look like this:...

XML Obtaining Namespaced node values

php,xml,simplexml
I have this xml fragment: <ModelList> <ProductModel> <CategoryCode>06</CategoryCode> <Definition> <ListProperties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <a:KeyValueOfstringArrayOfstringty7Ep6D1> <a:Key>Couleur principale</a:Key> <a:Value> <a:string>Blanc</a:string> <a:string>Noir</a:string> <a:string>Gris</a:string> <a:string>Inox</a:string> <a:string>Rose</a:string>...

SimpleXML deserialize Map

java,dictionary,simplexml
I have the XML: <?xml version="1.0" encoding="UTF-8"?> <addresses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='schema_task1_1.xsd'> <address> <name>Bill</name> <city>NewYork</city> <street>First</street> <phone type='mobile'>+19139130000</phone> <documents> <document type='driving_permit'>9045798749</document> <document type='passport'>3451231231</document> </documents>...

PHP Warning: main(): Node no longer exists

php,xml,simplexml
i´m looking for solution for my problem. I´m reading a xml feed which works fine, but sometime 1 node is missing. I always get an error in the logfile. I don´t want to turn off the complete error reporting. Can someone let me know, what´s the best way? Here is...

PHP Array & XML Can't get all content

php,arrays,xml,for-loop,simplexml
I'm tring to get all content from this xml: https://api.eveonline.com/eve/SkillTree.xml.aspx To save it on a MySQL DB. But there are some data missing... Could any1 that understand PHP, Array() and XML help me, please? This is my code to get the content: <?php $filename = 'https://api.eveonline.com/eve/SkillTree.xml.aspx'; $xmlbalance = simplexml_load_file($filename); $skills...

SimpleXML not returning attibutes

php,xml,simplexml
I'm tring to display the attributes for all items in an xml file. I have the following xml file: <OPupdate> <Version>Testing</Version> <VersionNumber>1.0</VersionNumber> <GenerationDate>2015-04-24T11:21:53.013</GenerationDate> <Product> <ProductID>P001</ProductID> <ProductAttribute> <Attribute ID="1" description="Att1" lang="en-GB" type="string" displaysequence="0">A</Attribute> <Attribute ID="2" description="Att2" lang="en-GB" type="string"...

How to parse an XML node with a colon tag using PHP

php,xml,simplexml,xmlreader
I am trying to fetch the value of the following nodes from [this URL (takes quite some time to load)][1]. The elements I'm interested in are: title, g:price and g:gtin The XML starts like this: <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"> <channel> <title>PhotoSpecialist.de</title> <link>http://www.photospecialist.de</link> <description/> <item> <g:id>BEN107C</g:id> <title>Benbo Trekker Mk3 + Kugelkopf +...

SimpleXml foreach : ignore element

php,arrays,xml,simplexml
<?php $xml = "<articles> <article id=\"18357302\"> <articleCategories> <articleCategory id=\"default\"/> <articleCategory id=\"66607\"/> </articleCategories> </article> </articles>"; $feed = simplexml_load_string($xml); $items = $feed->article; foreach ($items as $article) { // $categorie = $article->articleCategories->articleCategory[id]; $categories = $article->articleCategories; print_r($categories); echo "<br>print_r indeed returns an array, but impossible to echo...

add different children to an element in a xml file using php

php,xml,simplexml
I want to add some children to an element on my xml file like this : <test> <parameter type="double" name="PHONE_NUMBER" /> <parameter type="string" name="NAME" /> <parameter type="string" name="E-MAIL" /> ... </test> I've tried somthing like this : $input = simplexml_load_file('new.xml'); $input->test=""; $input->test->addChild("parameter"); $input->test->parameter->addAttribute("type", "double"); $input->test->parameter->addAttribute("name", "PHONE_NUMBER");...

SimpleXMLElement Add Child Closure

php,simplexml
I'm trying to create a simple XML document but I'm having difficulty grouping the children appropriately. My XML should look like this: <news> <abc> <content>test</content> </abc> <abc> <content2>test2</content2> </abc> </news> I'm using the following code: $newsXML = new SimpleXMLElement("<news></news>"); $news = $newsXML->addChild('abc'); $news->addChild('content','test'); $news->addChild('content2','test2'); echo $newsXML->asXML(); and getting this:...

Disenable, to extract data from SimpleXMLElement object [duplicate]

php,xml,xpath,simplexml
This question already has an answer here: SimpleXML: Selecting Elements Which Have A Certain Attribute Value 2 answers I'm extracting data from an xml file by using xpath in php so my code looks like this: xml = simplexml_load_file("CCV.xml"); foreach ($xml->xpath('./section[@label="Education"]/section[@label="Degrees"]') as $degrees) { var_dump($degrees); } Before switching to...

XPath does not work with XMLReader and SimpleXML? [duplicate]

php,xml,xpath,simplexml,xmlreader
This question already has an answer here: Load just XPath search to XMLReader memory? 1 answer I get feeds from an xml feeder and his XML structure is like this: <XMLSOCCER.COM> <OddsList> <Odds> <FixtureMatch_Id>346076</FixtureMatch_Id> <Bookmaker>Bet-At-Home</Bookmaker> <UpdatedDate>2015-06-20T19:42:32.943</UpdatedDate> <Type>Over/Under 2.5</Type> <HomeOdds>2.22</HomeOdds> <AwayOdds>1.58</AwayOdds> </Odds> <Odds>...

Scraping data using simple html dom and simpleXML

php,web-scraping,simplexml,simple-html-dom
I'm trying to scrape data from several links which i retrieve from a xml file. However i keep getting an error which only seem to appear on some of the news. below you can see the output i get http://www.hltv.org/news/14971-rgn-pro-series-groups-drawnRGN Pro Series groups drawn http://www.hltv.org/news/14969-k1ck-reveal-new-teamk1ck reveal new team http://www.hltv.org/news/14968-world-championships-captains-unveiled Fatal...

Why SimpleXML doesn't recognise fields with

php,xml,simplexml
I'm parsing XML with Simple XML, but there is name that it doesn't looks to understand, for instance XML <item> <art_id>34759</art_id> <kind>Car</kind> <tics.item.dimension>215/55 R 16</tics.item.dimension> </item> SIMPLE XML COMMAND echo $item->art_id; // works echo $item->tics.item.dimension; // does not work, it shows "itemdimension" but there is value so it should show...

How to parse following type of XML and store it into database using PHP

php,xml,simplexml
I have to parse this type of XML and store into the database. Please help. Here is the XML.. <?xml version='1.0' encoding='ASCII'?> <root> <mac>mac_n</mac> <ip_addr>ip_addr_n</ip_addr> <name1>Adobe AIR</name1> <version1>15.0.0.356</version1> <name2>Adobe Flash Player 16 PPAPI</name2> <version2>16.0.0.235</version2> </root> I want to parse this XML in such a manner that mac-address & ip gets...

Load just XPath search to XMLReader memory?

php,xpath,simplexml,xmlreader
Can i somehow do this? XMLReader is pull parser, so i expect from him to give me just data i search, but it loads whole document into memory and then gives me search from his memory. This code: $url = $this->buildUrl($name,$params); $xml = ''; $reader = new XMLReader(); $reader->open($url); $pathXML...

SimpleXML children's attributes behaves different with and without namespace

php,xml,simplexml
The SimpleXML examples page, section "Example #5 Using attributes" states: Access attributes of an element just as you would elements of an array. And the example #1 in SimpleXMLElement::children() works using $element['attribute'] syntax to access children's attributes; Adding a namespace to that code, will disable the access to attributes: $xml...

Simplexml: parsing HTML leaves out nested elements inside an element with a text node

php,xml,parsing,html-parsing,simplexml
I'm trying to parse a specific html document, some sort of a dictionary, with about 10000 words and description. It went well until I've noticed that entries in specific format doesn't get parsed well. Here is an example: <?php $html = ' <p> <b> <span>zot; zotz </span> </b> <span>Nista; nula....

Weird behaviour in SimpleXMLElement Object when printing the array

php,xml,simplexml,php-5.5
I'm struggling with an array in my SimpleXMLElement Object. Somehow I don't get the expected result when I print the array $node->reference. print_r($node); shows: SimpleXMLElement Object ( [reference] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [resourceIdentifier] => 52chgb7f-1a00-4eaf-ac8a-5d4557f9796a ) ) [1] => SimpleXMLElement Object (...

SimpleXML xpath to element with certain attribute value?

php,xml,xpath,xml-parsing,simplexml
I have some XML like this: <item> <custom-attributes> <custom-attribute attribute-id="taco">false</custom-attribute> <custom-attribute attribute-id="htmlContent" xml:lang="en-US">testValue</custom-attribute> <custom-attribute attribute-id="htmlContent" xml:lang="default">testing123</custom-attribute> </custom-attribute> </item> How do I use xpath to find the custom-attribute element than has an attribute-id of taco? How do I use xpath to find the custom-attribute element(s) than...

PHP xml working with ba.com API

php,xml,simplexml
I retrieve data from ba.com API using Flight Offer Market Affliates in xml format: $url="https://api.ba.com/rest-v1/v1/flightOfferMktAffiliates;departureDateTimeOutbound=".$Fwk->returnTrueDate($_POST['departureDate']). ";locationCodeOriginOutbound=".$_POST['departureMenu']. ";locationCodeDestinationOutbound=".$_POST['destination']. ";departureDateTimeInbound=".$Fwk->returnTrueDate($_POST['returnDate']). ";locationCodeOriginInbound=".$_POST['destination']....

Sort the order of an xml output using simpleXML

php,xml,sorting,order,simplexml
I'm working with XML file that is being used as "database". in this example it holds information about books. <?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102">...

Getting info from a specific XML Node

php,xml,simplexml
I am trying to read the value for 3 specific XML nodes (bill_codes, sent_total, clicked_unique_total) I have done a lot of testing and I feel like I need someone with fresh eyes to look at this and help me find out what I no longer see.. I am using the...

How to display a value from a SimpleXML object (the array notation is confusing me)

php,arrays,xml,simplexml,zoho
I have a PHP file that uses cURL to retrieve some XML. I now want to retrieve a value from the XML but I cannot traverse to it as I am confused with the notation. Here's my retrieved XML: SimpleXMLElement Object ( [@attributes] => Array ( [uri] => /fruit/apple/xml/green/pipType )...

Problems parsing xml with PHP and SimpleXML

php,xml,simplexml
I'm trying to parse a response from the Ontraport API, which is returned in an ugly XML format. <result> <contact id="1" date="1424746532" dlm="1425357692" score="0.00" purl="" bulk_mail="1"> <Group_Tag name="Contact Information"> <field name="Company">Test.com</field> <field name="Email">[email protected]</field> <field name="Group"/> <field name="Specialty"/> <field name="User ID"/> <field name="Display First"/> <field name="Display Last"/> </Group_Tag>...

Add SimpleXMLElement Object to Array

php,arrays,object,simplexml,sitemap
I have and object array as displayed below. Im having trouble adding to this object array as i keep getting an error. Here is how it is at the moment: SimpleXMLElement Object ( [url] => Array ( [0] => SimpleXMLElement Object ( [loc] => http://jbsoftware.co.uk/ [lastmod] => 2015-02-02 [changefreq] =>...