simplexml

Extract data from an XML object

只愿长相守 提交于 2020-01-06 05:09:07
问题 How do I extract the data from that XML object, which is a value of a certain array: Array ( [Title] => SimpleXMLElement Object ( [0] => The Key of Life; A Metaphysical Investigation ) [ASIN] => SimpleXMLElement Object ( [0] => 0982385099 ) ... ) I did a foreach of the array like: foreach ($ArrayName as $FieldLabel => $FieldValue) { $Variable = $FieldValue[0].... } ...but still, it gets the whole XML object as the field value. I wanted it to extract the value only not the whole object. 回答1:

Internal Server Error 500 simplexml_load_file

邮差的信 提交于 2020-01-05 08:29:18
问题 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/services/search/FindingService/v1): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in Command line code on line 1 PHP Stack trace: PHP

Simplexml_load_file errors

依然范特西╮ 提交于 2020-01-05 08:18:34
问题 I'm triying to parse this address in PHP $url = 'http://pubapi.yp.com/search-api/search/devapi/search?searchloc=91203&term=pizza&format=xml&sort=distance&radius=5&listingcount=10&key=t266jc29dx' ; $x1 = simplexml_load_file($url); But here's what I keep getting Warning: simplexml_load_file(http://pubapi.yp.com/search-api/search/devapi/search?searchloc=91203): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in... As you can see I'm only getting part of the url

Unable to remove all children from the XML document (PHP)

和自甴很熟 提交于 2020-01-05 05:58:07
问题 Unable to remove all children from the XML document <?xml version="1.0" encoding="UTF-8"?> <routes> <route name="admin" /> <!----> <route name="blog" bla bla/> <route name="blog" bla bla/> <route name="blog" bla bla/> </routes> $xml = simplexml_load_file('routes.xml'); $dom_sxe = dom_import_simplexml($xml); $dom = new \DOMDocument('1.0'); $dom_sxe = $dom->importNode($dom_sxe, true); $dom_sxe = $dom->appendChild($dom_sxe); foreach ($dom->getElementsByTagName('route') as $route) { if($route-

Parse through unknown XML

谁都会走 提交于 2020-01-05 04:15:10
问题 I've made a simple tool that lets you fill in an input field with a URL for an XML file. It's supposed to show all the nodes so the user can match them with database fields, which I have working for an XML file that has 2 "primary" nodes. Example of the XML file: <foods> <food> <name>ravioli</name> <recipe>food.com/ravioli</recipe> <time>10 minutes</time> </food> <food> <name>ravioli</name> <recipe>food.com/ravioli</recipe> <time>10 minutes</time> </food> </foods> This returns me a list that

insert xml data to mysql with simpleXML

醉酒当歌 提交于 2020-01-04 14:32:32
问题 I have to insert data from xml to database, but i have a problem with this specific data <specifications> <attribute_group name="attributeGroup1"> <attribute name="attribute1"> <value>value1</value> </attribute> <attribute name="attribute2"> <value>value2</value> </attribute> <attribute name="attribute3"> <value>value3</value> </attribute> </attribute_group> <specifications> I need to insert into database something like INSERT INTO specs (attr_group,attr_name, attr_value) VALUES ('$attr_group

Remove white spaces between tag values in xml with php

↘锁芯ラ 提交于 2020-01-04 06:29:10
问题 I been searching information how to remove white spaces between tag values leaved by a PHP code when I export it to XML, I will explain detailed, first I load and XML then I do a search on the file with xPath, then I remove some elements that do not match some brands and finally I reexport it as a new XML, the problem is that this new XML is full of white spaces leaved by the code. I tried trim it but it doesn't seems to work correctly. Here is my code: <?php $sXML = simplexml_load_file('file

SimpleXMLElement and Warning: Illegal offset type

余生长醉 提交于 2020-01-04 04:29:11
问题 Warning: Illegal offset type i have this var from an xml output var_dump($key); its give me object(SimpleXMLElement)#11 (1) { [0]=> string(5) "Cairo" } now i want make "Cairo" as a key to get its value like $lang[] = array('Cairo' => "Cairo city"); the error appear when do this echo $lang[$key]; and its give me the "Warning: Illegal offset type" because of the key is SimpleXMLElement how i can make it normal var? 回答1: Cast it to a string with (string)$key . 来源: https://stackoverflow.com

SimpleXML children's attributes behaves different with and without namespace

纵饮孤独 提交于 2020-01-03 12:35:34
问题 The SimpleXML examples page, section "Example #5 Using attributes" states: Access attributes of an element just as you would elements of an array. And the example #1 in SimpleXMLElement::children() works using $element['attribute'] syntax to access children's attributes; Adding a namespace to that code, will disable the access to attributes: $xml = new SimpleXMLElement( '<person xmlns:a="foo:bar"> <a:child role="son"> <a:child role="daughter"/> </a:child> <a:child role="daughter"> <a:child

SimpleXML children's attributes behaves different with and without namespace

北城以北 提交于 2020-01-03 12:35:04
问题 The SimpleXML examples page, section "Example #5 Using attributes" states: Access attributes of an element just as you would elements of an array. And the example #1 in SimpleXMLElement::children() works using $element['attribute'] syntax to access children's attributes; Adding a namespace to that code, will disable the access to attributes: $xml = new SimpleXMLElement( '<person xmlns:a="foo:bar"> <a:child role="son"> <a:child role="daughter"/> </a:child> <a:child role="daughter"> <a:child