simplexml

How to import XML string in a php DOMDocument

爷,独闯天下 提交于 2019-12-30 02:21:27
问题 For exemple, i create a DOMDocument like that : <?php $implementation = new DOMImplementation(); $dtd = $implementation->createDocumentType ( 'html', // qualifiedName '-//W3C//DTD XHTML 1.0 Transitional//EN', // publicId 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-' .'transitional.dtd' // systemId ); $document = $implementation->createDocument('', '', $dtd); $elementHtml = $document->createElement('html'); $elementHead = $document->createElement('head'); $elementBody = $document->createElement(

How to to sort a XML feed with SimpleXML

一世执手 提交于 2019-12-29 09:50:11
问题 I have started to use the simplexml function that seems to work out better than the previous other parser that I have tried to use. I have got to the stage where I need to the sort the items by transmissiondate - I tried using the uasort but does not make any changes the order of the items. also some times a programme is on more than once on the same day - would it be easier to sortby videoID can any help? this what the object looks like: [0] => SimpleXMLElement Object ( [VideoID] => 108059

Compare SimpleXml Object

做~自己de王妃 提交于 2019-12-28 06:49:29
问题 I'm trying to compare two SimpleXML Objects . One is fetched from DB and the other one from a XML API, but the result is always false, whether the XML are in fact identical or not. What am I doing wrong? $objDbXml = simplexml_load_string($objReisen->xml); // XML from DB $objApiXml = simplexml_load_string(getXMlFromApi()); // XML from Api var_dump($objDbXml->Reise->Z_LEISTUNGEN == $objApiXml->Reise->Z_LEISTUNGEN); // Result is always false The output of var_dump($objDbXml->Reise->Z_LEISTUNGEN

Is there a way to add a PHP SimpleXMLElement to another SimpleXMLElement?

微笑、不失礼 提交于 2019-12-28 04:28:33
问题 The "addChild" method of SimpleXMLElement seems like it should be the right choice, but it apparently only takes strings representing the tagname of the new child. There's the object-ish notation for referencing nodes of the tree and setting them, e.g. $simpleXMLNode->child = value, but that only seems to work for simple text/numeric values. If I try the following: $s = new SimpleXMLElement('<root/>'); $t = new SimpleXMLElement('<child/>'); $s->a = $t; echo $s->asXML() I get: <?xml version="1

How to prevent self closing tag in php simplexml

你离开我真会死。 提交于 2019-12-28 04:14:49
问题 I want to generate xml by using php simplexml. $xml = new SimpleXMLElement('<xml/>'); $output = $xml->addChild('child1'); $output->addChild('child2', "value"); $output->addChild('noValue', ''); Header('Content-type: text/xml'); print($xml->asXML()); The output is <xml> <child1> <child2>value</child2> <noValue/> </child1> </xml> What I want is if the tag has no value it should display like this <noValue></noValue> I've tried using LIBXML_NOEMPTYTAG from Turn OFF self-closing tags in SimpleXML

Simplexml_load_string() fail to parse error

一世执手 提交于 2019-12-28 04:05:08
问题 I'm trying to load parse a Google Weather API response (Chinese response). Here is the API call. // This code fails with the following error $xml = simplexml_load_file('http://www.google.com/ig/api?weather=11791&hl=zh-CN'); ( ! ) Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xB6 0xE0 0xD4 0xC6 in C:\htdocs\weather.php on line 11 Why does loading this response fail? How do I encode/decode

Format output of $SimpleXML->asXML(); [duplicate]

ε祈祈猫儿з 提交于 2019-12-28 03:39:05
问题 This question already has answers here : PHP simpleXML how to save the file in a formatted way? (4 answers) Closed 2 years ago . The title pretty much says it all. If I have something like (from PHP site examples): $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <movies></movies> XML; $sxe = new SimpleXMLElement($xmlstr); $sxe->addAttribute('type', 'documentary'); $movie = $sxe->addChild('movie'); $movie->addChild('title', 'PHP2: More Parser Stories'); $movie->addChild('plot', 'This

Get root node of XML doc using simplexml

末鹿安然 提交于 2019-12-28 03:06:02
问题 Using simplexml_load_string() how do I get "ForgotPassword" from the following XML? <?xml version="1.0" encoding="utf-8"?> <ForgotPassword> <version>1.0</version> <authentication> <login>username</login> <apikey>login</apikey> </authentication> <parameters> <emailAddress>joesmith@example.com</emailAddress> </parameters> </ForgotPassword> 回答1: Are you wanting to get the name of the root node? $xml = simplexml_load_string($str); echo $xml->getName(); 来源: https://stackoverflow.com/questions

Using SimpleXML to create an XML object from scratch

别说谁变了你拦得住时间么 提交于 2019-12-27 11:02:49
问题 Is it possible to use PHP's SimpleXML functions to create an XML object from scratch? Looking through the function list, there's ways to import an existing XML string into an object that you can then manipulate, but if I just want to generate an XML object programmatically from scratch, what's the best way to do that? I figured out that you can use simplexml_load_string() and pass in the root string that you want, and then you've got an object you can manipulate by adding children... although

How to edit my code to save to mySQL from the beginning of XML?

只愿长相守 提交于 2019-12-25 21:22:11
问题 I have this XML feed below I am trying to import into MySQL for all the products. For example, inside the table XML_FEED I want something like shop - product_id - product_name - product_link - ....... mywebstore - 322233 - MadBiker 600 - ......... mywebstore - 324633 - Samsung S4 - ......... The code until now it works only if the XML begins from <products> and not from <mywebstore> How to change my code to do this ? $xml = simplexml_load_file("test.xml"); foreach($xml->product as $product) {