simplexmlelement

Possible to add HTML content to SimpleXMLElement node

Hey all, Simple question. Is it possible to add a block of HTML in a SimpleXMLElement (or as a matter of fact, DOMDocument) node without auto-converting the HTML data into entity format? For example, take this snippet (with DOMDocument here, but SimpleXMLElement behaves exactly the same): <?php $dom = new DOMDocument( '1.0', 'utf-...

PHP get values from SimpleXMLElement array

I have this: [1]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(14) { ["name"]=> string(5) "MySQL" ["acknowledged"]=> string(1) "1" ["comments"]=> string(1) "1" ["current_check_attempt"]=> string(1) "1" ["downtime"]=> string(1) "0" ["last_check"]=> string(19) "2010-05-01 ...

php simplexmlelement get first element in one line

Just trying to figure a shorter way to do this: I'm using simpleXMLElement to parse an xml file and it's aggravating to have to call two lines to process an array when I know what node I want. Current code: $xml = new SimpleXMLElement($data); $r = $xml->xpath('///givexNumber'); $result["cardNum"] = $r[0]; What I would like to do wou...

SimpleXMLElement (PHP) throwing error on XML root attributes

I am working on a project that will take XML data submitted through a textarea input in a form then extract the data and throw it into a database. I am getting errors about the attribute in the root field of my XML (it is the same schema each time, but with different values). If i remove these attributes it works fine, but I don't want t...

php simplexmlelement - I can access most properties (except the one with a dash?)

So I run some code like this: $quote = simplexml_load_string($xml); $quote = $quote->Stock; echo 'Name: '; echo $quote->Name; echo '<br>'; echo 'Sybmol: '; echo $quote->Symbol; echo '<br>'; echo 'Last Price: '; echo $quote->Last; echo '<br>'; echo 'Earnings To Price Ratio: '; echo $quote->P-E; echo '<br>'; I know that the second to la...

reading xml: can xpath read 2 fields?

I'm using SimpleXMLElement and xpath to try and read the <subcategory><name> from the xml at the very bottom. This code works.. but the stuff inside the while loop looks a little messy, and now I also want to get the <subcategory><count> and somehow pair it with its appropriate <subcategory><name>. $names = $xml->xpath('/theroot/categor...

Using addChild with an index position

Hi guys, How can I choose it's position based on it's sibblings when I add a child node ? Here is an example : <?php $_XML = ' <Test> <Menu> <Link href="page1.htm" /> <Link href="page2.htm" /> <Link href="page4.htm" /> ...

How to get a simple SimpleXMLElement value

I'm aware of how to drill down into the nodes of an xml document as described here: http://www.php.net/manual/en/simplexml.examples-basic.php but am at a loss on how to extract the value in the following example $xmlStr = '<Error>Hello world. There is an Error</Error>'; $xml = simplexml_load_string($xmlStr); I'm sure it's something ...

SimpleXMLElement to modify root tag

Good day, I am having trouble modifying XML using SimpleXMLElement in PHP. My XML structure is as below: <chart caption='NULL' shownames='1' showvalues='0' decimals='2' numberPrefix='$' useRoundEdges='0' legendBorderAlpha='0' bgColor='FFFFFF' canvasBorderColor='A5A5A5' canvasBorderThickness='1' showToolTip='1'> ... </chart> How can ...

PHP, SimpleXML arrays. Unanticipated casting of an array to a string

Sample XML: <root> <ratings>3</ratings> <ratings>5</ratings> <ratings>7</ratings> </root> The following code is the basis for my small application, it works as would be expected: <?php // $xml is some simplexml object sizeof($xml->ratings); //3 foreach($xml->ratings as $rating){ echo($rating->value."::"); //thi...