simplexml

Parse error: syntax error, unexpected T_OBJECT_OPERATOR

瘦欲@ 提交于 2019-12-24 11:16:20
问题 I'm getting the following error when trying to add some data from myXml.xml to a string: Parse error: syntax error, unexpected T_OBJECT_OPERATOR. $xmlstr = file_get_contents('myXml.xml'); $xml = new SimpleXMLElement($xmlstr); foreach($xml->order as $order){ $replace = array(); $firstName = (string) $order->billing-address->first-name; $lastName = (string) $order->billing-address->last-name; } I can't provide my XML directly as it contains sensitive data. Thanks, Sam 回答1: The - sign means

php scripts gets a node value , if it equals specified value ; changes a node value has its same parent node

回眸只為那壹抹淺笑 提交于 2019-12-24 10:26:25
问题 just like the title I need help in a php script gets "name" node value , if it equals specified given value ; changes "rate" node value has its same "person" parent node. the xml file 'rate.xml' like the following <?xml version="1.0"?> <user> <person> <name>jessy</name> <rate>2</rate> </person> <person> <name>mice</name> <rate>5</rate> </person> </user> the script will be similar to this <?php $name = $_POST['name']; $like = $_POST['like']; $doc = new DOMDocument(); libxml_use_internal_errors

PHP SimpleXML repeated data

霸气de小男生 提交于 2019-12-24 10:01:10
问题 Using SimpleXML to pull data from a basic XML file. The XML looks something like: <shop> <section> <title></title> <products> <item> ... </item> </products> </section> </shop> I can load and loop out the nodes, but when I populate the HTML with each sections items it keeps repeating the first sections items. I'm confused because each section name is outputting correctly but using the first set of items. foreach($xml->section as $section){ $i=0; echo '<div class="section"><div class=

How to get the highest value of a specific tag in an XML file using SimpleXML?

被刻印的时光 ゝ 提交于 2019-12-24 09:40:08
问题 My XML file looks like this: <log> <entry entry_id="E200911115777"> <entry_data> <entry_title>Lorem ipsum dolor</entry_title> <entry_date>1999-04-15</entry_date> </entry_data> </entry> <entry entry_id="E205011115999"> <entry_data> <entry_title>Lorem ipsum dolor</entry_title> <entry_date>2004-12-15</entry_date> </entry_data> </entry> <entry entry_id="E199912119116"> <entry_data> <entry_title>Lorem ipsum dolor</entry_title> <entry_date>1990-11-20</entry_date> </entry_data> </entry> </log> I'm

Separate XML attributes in PHP

痴心易碎 提交于 2019-12-24 08:56:38
问题 I'm getting the XML attributes for sky_condition from this XML file: <METAR> <sky_condition sky_cover="SCT" cloud_base_ft_agl="1600"/> <sky_condition sky_cover="BKN" cloud_base_ft_agl="2200"/> </METAR> Using the PHP code: $sky = $xml->data->METAR[0]->sky_condition->attributes(); (I've removed extra XML code) And I'm using this to output the data: <table border="0"> <?php foreach ($sky as $sky_cover => $cloud_base_ft_agl){ echo"<tr>"; echo"<td><strong>"; if ($sky_cover == "CAVOK") {echo

auto increment for simpleXML

主宰稳场 提交于 2019-12-24 07:38:09
问题 I have my simpleXML script creating new element's in a xml file but I need the attribute to be a auto incremented id for example <gig id="1"> <date>December 19th</date> <venue>The Zanzibar</venue> <area>Liverpool</area> <telephone>Ticketline.co.uk</telephone> <price>£6</price> <time>Time TBA</time> </gig> Is correct but when I create a new elemenet the id has to be written in by myself. My code is as followed $line1 = $sxe->addChild('gig'); $line1->addChild('id', HERE HERE HERE!!!!!!); $line1

converting text file into xml using php?

送分小仙女□ 提交于 2019-12-24 04:51:49
问题 data.txt ha15rs,250,home2.gif,2 ha36gs,150,home3.gif,1 ha27se,300,home4.gif,4 ha4678,200,home5.gif,5 i want convert this textfile into xml using simplexml module using php? thanks :)) p.s. im new to this EDIT: <allproperty> <aproperty> <postcode></postcode> <price></price> <imagefilename></imagefilename> <visits></visits> </aproperty> <aproperty> <postcode></postcode> <price></price> <imagefilename></imagefilename> <visits></visits> </aproperty> <aproperty> <postcode></postcode> <price><

SimpleXML - add a new node using a namespace previously declared - how?

旧街凉风 提交于 2019-12-24 04:23:32
问题 I would like to add a child, on a very specific place (so I'm also using DOM and not only simpleXML) for <domain:create> node. I have tried to use the $ns attribute on simpleXML construct. $nsNode = new SimpleXMLElement('<domain:ns>', $options = 0, $ns='urn:ietf:params:xml:ns:domain-1.0'); //transform the target into dom object for manipulation $nodeRegistrantDom = dom_import_simplexml($nodeRegistrant); But I'm getting: I/O warning : failed to load external entity "<domain:ns>" I've tried to

XML File - Get specific child nodes in unlimited node depths

不羁岁月 提交于 2019-12-24 03:52:33
问题 I'm working on a website that uses hierarchical data. After struggling to do it with MySQL databases (really complicated...), I decided to dive into XML because it sounds like XML works perfectly for my needs. Now I'm experimenting with an XML File and SimpleXML. But first of all, here is what my XML File looks like: <?xml version="1.0" encoding="ISO-8859-1" ?> <content> <parent> <child id="1"> <title>child 1</title> <child id="1"> <title>child 1.1</title> <child id="1"> <title>child 1.1.1<

Parse RDF XML file to get all rdf:about values

*爱你&永不变心* 提交于 2019-12-24 03:17:31
问题 I am using php's simple xml and xpath to parse an rdf xml file and am struggling to get a list of all the rdf:about values. Any advice? 回答1: There seems to be an issue when using SimpleXml with namespaced attributes prior to PHP5.3. Basically, anything with a : will be dropped when converted to an object property of a SimpleXml element. The following will do, but feels hackish to me: $rdf = str_replace('rdf:about', 'rdf_about', $rdf); $rdf = new SimpleXMLElement($rdf); foreach($rdf->xpath('//