simplexml

Quickly convert simpleXMLObject to STDClass?

Does anybody know a quick way to convert a SimpleXMLElement to a normal STDClass object, without iterating through each branch manually? I would feel better working with a normal object after fetching the data. ...

unable add namespace with php's simplexml

Hi , I am creating an atom feed , when I tried below to add xmlns:i as an attribute - $node->addAttribute("xmlns:i","http://www.w3.org/2001/XMLSchema-instance"); I got this as an output - i="http://www.w3.org/2001/XMLSchema-instance" "xmlns:" par was cut off. do I need to escape : char ? or is they any other way to add this namesp...

Accessing SimpleXML Object attribute

Have this print output from print_r($theobject); SimpleXMLElement Object ( [@attributes] => Array ( [label] => a ) [0] => Abnormal psychology : Abnormal psychology : ) Just cannot find a way to get element 0 which is "Abnormal psychology :" Lets call the object as $theobject I did $theobject[0], ...

Supply a different DTD location to SimpleXML / DOM for XML parsing

I have a problem with supplied XML files which don't have the right location in the XML. I'm trying to get correct XML files, but we might not succeed in getting those so I am looking at alternative solutions. As the DTD is available online, I could do a regex on the XML file and replace the DTD location, but this feels a bit hackish, an...

Auto-repeat structures using simpleXML?

I am defining the elements of form in a simple XML structure like so: <subtab id="page_background" label="Page Background" prefix="page"> <input label="Background color" field="bgcolor" type="color"/> <input label="Background image" field="bgimage" type="image"/> <space /> </subtab> etc. I have large blocks containing abs...

nested xml document in Simplexml document

Hi, I have a problem when using simplexml to read a xml document that I am getting back from a webservice call. Reading the data is fine however one node called UserArea contains a nested XMLdocument which contains namespaces. From this question on SO I've looked at how to deal with child nodes. However when I call the node that has t...

PHP SimpleXml Elements to Array

Hello, I need to send a string of html has is like <total> <tag>content</tag> <tag2 ref="333"> <code>somecode</code> <code>morecode</code> </tag2> <tag3> more code </tag3> </total> This would go into an array like : $arra[] = "<tag>content</tag>"; $arra[] = "<tag2 ref="333">"; $arra[] = "<code ... etc But I'm not figuring out how to...

Accessing @attribute from SimpleXML

Hi, I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and when I var_dump the rest of the object (the nested tags), I get the correct output, but when I follow the docs and var_dump $xml->OFFICE->{'@attributes'}, I get an empty object, despite the...

Need some help with XML parsing

The XML feed is located at: http://xml.betclick.com/odds%5Ffr.xml I need a php loop to echo the name of the match, the hour, and the bets options and the odds links. The function will select and display ONLY the matchs of the day with streaming="1" and the bets type "Ftb_Mr3". I'm new to xpath and simplexml. Thanks in advance. So far...

How to shut up simpleXML on malformed data?

I have a XML setting I am trying to load using simplexml. The XML setting can be edited by the user of a web application. I want to handle errors myself and dispatch a warning message to the user interface. However, simplexml keeps throwing warnings on malformed XML instead of quietly returning false. How can I make simpleXML shut up a...

navigating through this xml structure with php

Im trying to loop through and display info from the following xml structure. <users_list> −<users type="array"> +<user> <id>Blah</id> </user> +<user></user> +<user></user> </users> <next_link>6</next_link> <prev_link>4</prev_link> </users_list> Im using the following PHP to grab the nodes. $xml = simpl...

problem with simpleXMLElement

Here is my PHP code $xml= new SimpleXmlElement($rawxml); foreach($xml->children()->children() AS $key){ $id = $xml->{"id"}; $name = $xml->{"screen_name"}; $profimg = $xml->{"profile_image_url"}; echo "$id, $name, $profimg"; } $next = $xml->{"next_link"}; echo "index.php?".$next; Here is the structure of my xml <?xml version...

simplexml + foreach +twitter with unexpected results

Im using the following code to output all the nodes from the xml shown. $cursor = "?cursor=-1" $xml= new SimpleXmlElement($to->OAuthRequest('http://twitter.com/statuses/followers.xml?$cursor')); foreach ($xml->xpath('/users_list/users/user') as $user) { $id = $user->id; $names .= $user->screen_name; $profimg = $...

XPATH / PHP trouble with last()

I've tried reading various tutorials online but I can't make any headway on solving this issue which is easy to describe but which I can not conceive of a solution. Here is some sample XML: <AAA> <BBB> <CCC>1</CCC> <CCC>2</CCC> </BBB> <BBB> <CCC>3</CCC> <CCC>4</CCC> </BBB> </AAA> I want...

Retrieving attributes from a SimpleXMLElement

How would I get to the name variable given the object. $obj->@attributes['name']; would obviously not work. SimpleXMLElement Object ( [@attributes] => Array ( [name] => Address ) [value] => Address ) ...

Inject XML into a node using a string

I am rebuilding a nodes children by saving them out to an array as strings, trashing them in the XML, inserting a new child node into the array as a string... now I want to loop through the array and write them back out to the original node. The problem is I can't find anything on how to add a child node using a string. See below for ...

Cached XML for PHP?

I have a custom PHP framework and am discovering the joys of storing configuration settings as human-readable, simple XML. I am very tempted to introduce XML (really simple XML, like this) <mainmenu> <button action="back" label="Back"/> <button action="new" label="New item"/> </mainmenu> in a number of places in the framework. It i...

PHP SimpleXML XPath contains() to find other elements referenced by this element

Hi Guys ang Gals, I'm being given XML in the following format, and am parsing it with PHP's SimpleXML. <?xml version="1.0" encoding="UTF-8"?> <ManageMyBooking> <BookingInfo> <PartyDetails> <Passenger> <PaxNo>1</PaxNo> <Title>Mrs</Title> <Surname>Murphy</Surname> ...

php: parsing table structure with SimpleXML

Hi, I'm trying to read in an xml file that for some reason has been modeled in a table structure like so: <tr id="1"><td name="Date">10/01/2009</td><td name="PromoName">Sample Promo Name</td><td name="PromoCode">Sample Promo Code</td><td name="PromoLevel" /></tr> This is just one sample row, the file has multiple <-tr-> blocks and it'...

Filtering a structure in XML by attribute

I have a nested simple XML structure that I load with PHP's simpleXML. Some elements of the structure contain "context" attributes. <tab context="new_item, edit_item"> <input type="text" context="new_item"> <input type="readonly" context="edit_item"> <tab context="new_item"> ... </tab> </tab> After loading, I need ...