simplexml

simplexml_load_file parse [@attributes] => Array

时光毁灭记忆、已成空白 提交于 2019-12-17 20:43:03
问题 I am trying to parse this xml feed [0] => SimpleXMLElement Object ( [title] => Johannesburg in November [link] => SimpleXMLElement Object ( [@attributes] => Array ( [rel] => alternate [type] => text/html [href] => http://www.tompeters.com/dispatches/012120.php?rss=1 ) ) [id] => tag:www.tompeters.com,2011://2.12120 [published] => 2011-09-08T14:03:23Z [updated] => 2011-09-08T14:11:49Z [summary] => Tom will be giving a day-long presentation in November in Johannesburg, South Africa. Our friends

PHP SimpleXML doesn't preserve line breaks in XML attributes

[亡魂溺海] 提交于 2019-12-17 20:19:50
问题 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 file script (note that when the line breaks are not in an attribute they are preserved). PHP File with embedded XML $xml = <<<XML <?xml version="1.0" encoding="utf-8"

Using xpath on a PHP SimpleXML object, SOAP + namespaces (not working..)

天涯浪子 提交于 2019-12-17 16:43:22
问题 After researching this on SO and google for hours now... I hope to get some help here: (I am just one step away from running a regex to remove the namespaces completely) First this is the XML: <?xml version="1.0" encoding="utf-16"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header xmlns="http://webservices.site.com/definitions"> <SessionId>0119A|1</SessionId> </soap:Header> <soap:Body> <Security_AuthenticateReply xmlns="http://xml.site.com/QQ">

SimpleXmlElement and XPath, getting empty array()

巧了我就是萌 提交于 2019-12-17 16:28:14
问题 I am having a little trouble with parsing XML from a google checkout response. The XML is coming straight from the google server so there is no problem with the XML itself. I want to get hold of all the new-order-notification tags I tried this but get an empty array() returned everytime. $xml = new SimpleXmlElement($raw_xml); $notifications = $xml->xpath('notifications'); $notifications = $xml->xpath('/notification-history-response/notifications/new-order-notification'); $notifications = $xml

Looping through a SimpleXML object, or turning the whole thing into an array

橙三吉。 提交于 2019-12-17 15:57:10
问题 I'm trying to work out how to iterate though a returned SimpleXML object. I'm using a toolkit called Tarzan AWS, which connects to Amazon Web Services (SimpleDB, S3, EC2, etc). I'm specifically using SimpleDB. I can put data into the Amazon SimpleDB service, and I can get it back. I just don't know how to handle the SimpleXML object that is returned. The Tarzan AWS documentation says this: Look at the response to navigate through the headers and body of the response. Note that this is an

Getting the text portion of a node using php Simple XML

可紊 提交于 2019-12-17 13:02:27
问题 Given the php code: $xml = <<<EOF <articles> <article> This is a link <link>Title</link> with some text following it. </article> </articles> EOF; function traverse($xml) { $result = ""; foreach($xml->children() as $x) { if ($x->count()) { $result .= traverse($x); } else { $result .= $x; } } return $result; } $parser = new SimpleXMLElement($xml); traverse($parser); I expected the function traverse() to return: This is a link Title with some text following it. However, it returns only: Title Is

XPath in SimpleXML for default namespaces without needing prefixes

不羁岁月 提交于 2019-12-17 12:06:10
问题 I have an XML document that has a default namespace attached to it, eg <foo xmlns="http://www.example.com/ns/1.0"> ... </foo> In reality this is a complex XML document that conforms to a complex schema. My job is to parse out some data from it. To aid me, I have a spreadsheet of XPath. The XPath is rather deeply nested, eg level1/level2/level3[@foo="bar"]/level4[@foo="bar"]/level5/level6[2] The person who generate the XPath is an expert in the schema, so I am going with the assumption that I

XML parser error: entity not defined

浪子不回头ぞ 提交于 2019-12-17 10:49:43
问题 I have searched stackoverflow on this problem and did find a few topics, but I feel like there isn't really a solid answer for me on this. I have a form that users submit and the field's value is stored in a XML file. The XML is set to be encoded with UTF-8. Every now and then a user will copy/paste text from somewhere and that's when I get the "entity not defined error". I realize XML only supports a select few entities and anything beyond that is not recognized - hence the parser error.

How do you rename a tag in SimpleXML through a DOM object?

大城市里の小女人 提交于 2019-12-17 09:58:14
问题 The problem seems straightforward, but I'm having trouble getting access to the tag name of a SimpleXMLElement. Let's say I have the follow XML structure: <xml> <oldName>Stuff</oldName> </xml> And I want it to look like this: <xml> <newName>Stuff</newName> </xml> Is this possible to do without doing a copy of the entire object? I've started to realize the errors of the ways I am approaching this problem. It seems that I need to convert my SimpleXMLElement into a DOM object. Upon doing so I

Sort XML via attribute value PHP

半世苍凉 提交于 2019-12-17 09:52:50
问题 So I have an XML file that I am trying to loop through in order, according to the attribute, "order". Here is an example: <page> <talentTrees> <tree name="Football" order="2"> <tree name="Baseball" order="0"> <tree name="Frisbee" order="1"> </talentTrees> </page> My goal is to loop through each "tree" using foreach, but I want to read them in order of the order attribute: Baseball, Frisbee, Football. (0,1,2). Sorry for poor English, not my first language. 回答1: This should give you what you