simplexml

using data from child element to select data in other element using simplexml in php

情到浓时终转凉″ 提交于 2019-12-25 18:39:29
问题 So, I'm using simplexml in php to display elements from an xml file onto a webpage. This is working fine when selecting a whole list child elements in one certain element. The thing is however, I need to select a number of rules in one element, and display the data attached to these certain rules found in another element. To clarify, this a simplified version of my xml file (it contains everything I need): <report> <profile_info> <rules> <rule id="RUL1"> <display_name> XMP does not have

what does means symbol “@” in this output?

时光总嘲笑我的痴心妄想 提交于 2019-12-25 17:44:46
问题 SimpleXMLElement Object( [ImageFormat] => SimpleXMLElement Object( [@attributes] => Array( [DimensionCategory] => small [Title] => extra ) [URL] => link.. ) ) 回答1: @attributes is derived from this <ImageFormat DimensionCategory="small" Title="extra"> <URL /> </ImageFormat> in another word, is attributes of a given element see this 回答2: As knittl stated, it's just a member name. As a note: to access attributes in a SimpleXML node, instead of doing: echo $xml->ImageFormat->{'@attributes'}[

SimpleXML PHP Parsing [duplicate]

孤街醉人 提交于 2019-12-25 17:21:25
问题 This question already has an answer here : Closed 7 years ago . It IS a duplicate, just not for the question that is was closed for. Finally found the answer, even here on SO. Actual Duplicate: PHP SimpleXML Namespace Problem EDIT: If you read the question closely, you will see it is NOT a duplicate of PHP namespace simplexml problems. The answer from the 'possible duplicate' is not the answer to my question. Again: I have no problem with $value = $record->children('cap', true)->$title; .

PHP SimpleXML Getting a child node attribute based on a node attribute

不羁岁月 提交于 2019-12-25 09:59:52
问题 I'm trying to loop through an XML file formatted like so: <colors> ... </colors> <sets> <settype type="hr" paletteid="2" mand_m_0="0" mand_f_0="0" mand_m_1="0" mand_f_1="0"> <set id="175" gender="M" club="0" colorable="0" selectable="0" preselectable="0"> <part id="996" type="hr" colorable="0" index="0" colorindex="0"/> </set> ... </settype> <settype type="ch" paletteid="3" mand_m_0="1" mand_f_0="1" mand_m_1="0" mand_f_1="1"> <set id="680" gender="F" club="0" colorable="1" selectable="1"

xml parsing with php

家住魔仙堡 提交于 2019-12-25 09:32:11
问题 I would like to create a new simplified xml based on an existing one: (using "simpleXml") <?xml version="1.0" encoding="UTF-8"?> <xls:XLS> <xls:RouteInstructionsList> <xls:RouteInstruction> <xls:Instruction>Start</xls:Instruction> </xls:RouteInstruction> </xls:RouteInstructionsList> <xls:RouteInstructionsList> <xls:RouteInstruction> <xls:Instruction>End</xls:Instruction> </xls:RouteInstruction> </xls:RouteInstructionsList> </xls:XLS> Because there are always colons in the element-tags, it

How to import XML using PHP?

蹲街弑〆低调 提交于 2019-12-25 06:55:08
问题 I've been creating a simple website for a client (I'm a designer with front-end skills) but I've been thrown a curve ball and now they want a catalogue of products imported via a CSV or XML file. I've chosen the XML option as I have even less of a clue what to do with the CSV. Would love some guidance on how I can start pulling out the XML using PHP. XML product example: <?xml version="1.0" encoding="ISO-8859-1"?> <style body="Neck%2C+waist+and+cuff+ribs+in+cotton%2FLycra%C2%AE%0ATwin+needle

Foreach loop with xPath on SimpleXML object returning duplicate data

*爱你&永不变心* 提交于 2019-12-25 06:52:15
问题 Can anyone help explain to me why the following is returning duplicate data? <?php $xml_test = '<array key="results"> <array key="123"> <string key="mask">1234</string> </array> <array key="987"> <string key="mask">5678</string> </array> </array>'; $load_test = simplexml_load_string($xml_test); foreach ($load_test as $array) { $mask = $array->xpath('//string[@key="mask"]'); print 'Mask: ' . $mask[0] . '<br />'; } Returns: Mask: 1234 Mask: 1234 If I throw a print_r($array) within the foreach

Extracting data from XML using SimpleXML, third-level

孤街浪徒 提交于 2019-12-25 04:45:30
问题 I'm trying to extract data from an xml file. The problem is I know how to do the second level, but not a third level. Here's a sample test of the XML <createacct> <result> <options> <ns></ns> </options> <rawout> stuff </rawout> <status>1</status> <statusmsg>success</statusmsg> </result> </createacct> Now, how would I extract the data from: <rawout> , <status> and <statusmsg> ? I may need to look at <result><options><ns> as well. I suppose maybe: $yop = new SimpleXMLElement ($xmlFile); $rawout

Getting value from a SimpleXMLElement object

妖精的绣舞 提交于 2019-12-25 04:43:34
问题 I have $number[0] which is a object(SimpleXMLElement) type. It has just one element. The element has this pair 0 -- 9 9 is a string I need to have in a variable. 回答1: If you want to access anything in your SimpleXMLElement , you will have to access it like an object. i.e $value = $xml->foo->bar->baz; This is desribed in more detail at the official documentation for SimpleXML 来源: https://stackoverflow.com/questions/8230894/getting-value-from-a-simplexmlelement-object

Parse weather data from Weatherbug in PHP

若如初见. 提交于 2019-12-25 04:39:29
问题 Greetings, I am trying to parse live weather data from Weatherbug's RSS feed in PHP. I had previously used simplexml_load_string() with NOAA's weather data but I cannot figure out how to output the data that I need from Weatherbug. Here is the XML for current conditions: <rss version="2.0" xmlns:georss="http://www.georss.org/georss"> <channel> <title>Observations from Saint Inigoes, MD - USA</title> <link>http://weather.weatherbug.com/MD/Saint Inigoes-weather.html?ZCode=Z5546&Units=0&stat