simplexml

Missing characters in parsed XML output with PHP5

I'm trying to parse the following XML file: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE content PUBLIC "-//BLACKWELL PUBLISHING GROUP//DTD 4.0//EN" "http://www.blackwellpublishing.com/xml/dtds/4-0/bpg4-0.dtd"&gt; <content dtdver="4.0" docfmt="xml"> .... <forenames>NIELS B&Oslash;IE</forenames><x> </x> At first it wouldn't lo...

Internal Server Error 500 simplexml_load_file

if I use Firefox and access http://svcs.ebay.com/services/search/FindingService/v1 I get some sort of XML in respose, when I do that through PHP I get Internal Server Error 500 $ php -r 'print_r(simplexml_load_file("http://svcs.ebay.com/services/search/FindingService/v1"));' PHP Warning: simplexml_load_file(http://svcs.ebay.com/servic...

PHP SimpleXML doesn't preserve line breaks in XML attributes

I have to parse externally provided XML that has attributes with line breaks in them. Using SimpleXML, the line breaks seem to be lost. According to another stackoverflow question, line breaks should be valid (even though far less than ideal!) for XML. Why are they lost? [edit] And how can I preserve them? [/edit] Here is a demo fil...

php simplexml_load_file

I'm new to PHP and this may be a stupid question to ask, so don't vote me down just because I don't understand something... php -r "print_r(simplexml_load_file('http://twitter.com/statuses/user_timeline/31139114.rss'));" let's take this for an example, by running this command i get (on screen) XML output. my question is it possible t...

How fast is simplexml_load_file()?

Hi. I'm fetching lots of user data via last.fm's API for my mashup. I do this every week as I have to collect listening data. I fetch the data through their REST API and XML: more specifically simplexml_load_file(). The script is taking ridiculously long. For about 2 300 users, the script takes 30min to fetch only the names of artists....

Parsing XML with PHP and SimpleXML where items are named <long>, <float> or <int>

I'm trying to parse data from Archive.org's search functionality. The data looks like this: <doc> <float name="avg_rating">5.0</float> <arr name="collection"><str>U-Melt</str><str>etree</str></arr> <arr name="format"><str>Checksums</str><str>Flac</str><str>Flac FingerPrint</str> <str>Metadata</str><str>Ogg Vorbis</str><st...

How to get only required xpath elements?

Hi Guys, I have an xml file that I want to store a node's rank attribute in a variable. I tried: echo $var = $xmlobj->xpath("//Listing[@rank]"); to no avail, it just prints ArrayArray. How can this be done? if($xmlobj = simplexml_load_string(file_get_contents($xml_feed))) { foreach($xmlobj as $listing) { ...

PHP, json_encode, json_decode of SimpleXML Object

A function in my application does the following: Capture Web Page using Snoopy Load result into DOMDocument Load DOMDocument into Simple XML Object Run XPath to isolate section of document required json_encode the result and save to database for later use. My problem arises when recovering this block from the database, and decoding i...

I'm having trouble parsing a facebook feed using simplexml

http://www.facebook.com/feeds/share_posts.php?id=207302593&amp;viewer=207302593&amp;key=d95b2de790&amp;format=rss20 The link above is the URL to my shared posts on Facebook. When I load that URL in to simplexml_load_file() it provides an entire page of errors. Looking at the errors, it looks like Facebook is spitting out HTML instead of...

Cannot parse poorly formed XML

I've been trying to parse this feed. If you click on that link, you'll notice that it can't even parse it correctly in the browser. Anyway, my hosting service won't let me use simplexml_load_file, so I've been using cURL to get it then loading the string into the DOM, like this: $dom = new DOMDocument; $dom->loadXML($rawXML); if (!$dom...

CURL/PHP/Apache - Why won't this CURL/Simplexml request to Vimeo work?

The below function should be outputting a Vimeo thumbnail. Its not returning anything. I have tested for $id and it is passing into the function, and it is a valid vimeo ID for a video. When I replace the $out = xxx with $out = 'hello'; , nothing comes out. This leads me to believe no records are being returned in the xml call. Curl...

How do you get the object name when using SimpleXML?

If the format is the following, where c is an object array that I must foreach through each iteration: $a->b->c And I do: $z = $a->b foreach($z as $key => $value) echo $value['field']; $key comes up as null, even though I have valid values. How do I get the name of the object? ...

get list of children in SimpleXMLElement PHP

how do i get the list of children in xml->request->ABC ABC may have DEF, ZZA, XAS, ETC and i would like to iterate through a list of these children (name required) instead of checking if they exist. -edit- Note: I am looking for the element name. I found an example which returns an attribute IF its known. How do i get the tag/element na...

php XML and hash/associate arrays

Using PHP's SimpleXML i would like to get the key and child of an element. The first element if there are more then one. How do i do this? the 2nd line doesnt make sense so how would get the first key/val of the first element? $body = $xml->Body; $xml->Body->children() as $XX=>$ZZ; echo "x $XX $ZZ\n"; foreach($xml->Body->children() as $...

Accessing HTML inside XML using SimpleXML in PHP

Hi, I'm having a problem with SimpleXML. When I'm using the children() method to get the contents of an XML element, with elements that contain HTML, it will parse the HTML contents as XML. How would I make it so that it won't parse HTML? ...

How can I reference elements with names like 'element-name' using SimpleXml

How can I parse an XML document like this: <feed> <item> <element-name>Element value</element-name> </item> </feed> If I try the following, it doesn't work: $xmlObject = simplexml_load_string($xmlString); foreach($xmlObject->item as $item) { $elementName= $item->element-name; // Obviously doesn't work. } I've tried: $...

php SimpleXML check if a child exist

A->b->c might exist but c might not exist. How do i check it? ...

Pulling out a full node with child nodes using XPath

I'm using XPath to select an section from an HTML page. However when I use XPath to extract the node, it correctly selects only the text surrounding the HTML tags and not the HTML tags themselves. Sample HTML <body> <div> At first glance you may ask, &#8220;what <i>exactly</i> do you mean?&#8221; It means that we want ...

simplyXML and accented characters in PHP

I have written an XML file which is using the ISO-8859-15 encoding and most of the data within the feed is ran through htmlspecialchars(). I am then using simplyxml_load_string() to retrieve the contents of the XML file to use in my script. However, if I have any special characters (ie: é á ó) it comes out as "é á ó". The How can I ...

PHP library for parsing XML with a colons in tag names?

I've been trying to use SimpleXML, but it doesn't seem to like XML that looks like this: <xhtml:div>sample <xhtml:em>italic</xhtml:em> text</xhtml:div> So what library will handle tags that look like that (have a colon in them)? ...