simplexml

php xpath with text() and SimpleXMLElement->xpath not in line with xpath expected results

南笙酒味 提交于 2019-12-22 08:37:34
问题 I'm trying to get all text nodes of /td/span. I'm trying with xpath /td/span/text() The problem is it's returning ALL the text nodes for every text element (there are two here, "193" and "120", it returns "193120" twice, instead of 193 and 120 in separate elements). I try the exact same xpath on any online tool, it works fine, in php, completely different results. using SimpleXMLElement $xhtmlSnippet = '<td><span>193<span>10</span><span></span><div>66</div><span>195</span><span>.</span><span

simplexml_load_file not working

纵然是瞬间 提交于 2019-12-22 05:17:30
问题 I have this piece of code below which works fine on my remote hosted server, but isnt for some reason working on my local linux machine. Ive tried using file_get_contents as well to get the restful service but it also returns false. Does anyone know Why this is happening? thanks :) $xml_data = simplexml_load_file("****"); if ($xml == FALSE) { echo "Failed loading XML\n"; foreach (libxml_get_errors() as $error) { echo "\t", $error->message; } } 回答1: You are getting this error because remote

Enumerate registered namespaces of a PHP DOMDocument object

浪子不回头ぞ 提交于 2019-12-21 17:01:05
问题 For one of my projects, I'm using the DOMDocument class to load and manipulate XML documents. I'd need to retrieve every namespace used in the document; however, I can't find how I'd do that. The DOMDocument class has methods to get the namespace prefix of an URI or the URI of a namespace prefix, but I've seen nothing to actually enumerate registered namespaces. The SimpleXML library has a getNamespaces() method for that. Is there an equivalent for DOMDocument ? 回答1: DOM does not have such a

How to keep DOMDocument from saving < as &lt

雨燕双飞 提交于 2019-12-21 04:29:20
问题 I'm using simpleXML to add in a child node within one of my XML documents... when I do a print_r on my simpleXML object, the < is still being displayed as a < in the view source. However, after I save this object back to XML using DOMDocument, the < is converted to < and the > is converted to > Any ideas on how to change this behavior? I've tried adding dom->substituteEntities = false; , but this did no good. //Convert SimpleXML element to DOM and save $dom = new DOMDocument('1.0'); $dom-

Bulletproofing SimpleXMLElement

徘徊边缘 提交于 2019-12-21 01:59:31
问题 Everyone knows that we should always use DOM techniques instead of regexes to extract content from HTML, but I get the feeling that I can never trust the SimpleXML extension or similar ones. I'm coding a OpenID implementation right now, and I tried using SimpleXML to do the HTML discovery - but my very first test (with alixaxel.myopenid.com) yielded a lot of errors: Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 27: parser error : Opening and ending tag

SimpleXML vs DOMDocument performance

跟風遠走 提交于 2019-12-20 23:29:22
问题 I am building an RSS parser using the SimpleXML Class and I was wondering if using the DOMDocument class would improve the speed of the parser. I am parsing an rss document that is at least 1000 lines and I use almost all of the data from those 1000 lines. I am looking for the method that will take the least time to complete. 回答1: SimpleXML and DOMDocument both use the same parser ( libxml2 ), so the parsing difference between them is negligible. This is easy to verify: function time_load_dd(

SimpleXMLElement Object [closed]

南笙酒味 提交于 2019-12-20 07:59:03
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . When I do print_r($nodes); I get: Array ( [0] => SimpleXMLElement Object ( [kategoria_6] => 1 [opis_6] => 1 [img] => slides/slide0.jpg ) [1] => SimpleXMLElement Object ( [kategoria_6] => 2 [opis_6] => 2 [img] =>

PHP - Simple XML - Nested Hierarchy

倖福魔咒の 提交于 2019-12-20 07:27:07
问题 I have been using PHP's simple XML function to work with an XML file. The below code works fine for a simple XML hierarchy: $xml = simplexml_load_file("test.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } This assumes the structure of the XML document is as follows: <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!<

PHP/SimpleXML/XPath get attribute value by another attribute in same element

老子叫甜甜 提交于 2019-12-20 06:37:15
问题 I have this XML (from a pptx file): <Relationships> <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image2.png"/> <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image1.wmf"/> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/> </Relationships> I

Parsing XML with multiple namespaces

随声附和 提交于 2019-12-20 06:27:02
问题 So I wanted to parse this XML: <?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <requestContactResponse xmlns="http://webservice.foo.com"> <requestContactReturn> <errorCode xsi:nil="true"/> <errorDesc xsi:nil="true"/> <id>744</id> </requestContactReturn> </requestContactResponse> </soapenv:Body> </soapenv:Envelope>