simplexml

SimpleXMLElement to PHP Array [duplicate]

佐手、 提交于 2020-01-09 10:14:41
问题 This question already has answers here : Recursive cast from SimpleXMLObject to Array (5 answers) Closed 4 years ago . Variable $d comes from file_get_contents function to a URL. $answer = @new SimpleXMLElement($d); Below is output of the print_r($answer) : SimpleXMLElement Object ( [Amount] => 2698 [Status] => OK [State] => FL [Country] => USA ) How can I retrieve value of each element and add to an array? I can't figure it out. 回答1: The $answer can already work as an array. You can do this

php SimpleXML attributes are missing

ε祈祈猫儿з 提交于 2020-01-09 03:57:04
问题 I have the following xml document here: Edit: (see below for sample) I am using php/SimpleXML to covert it to an object to read it: $xmlContent = file_get_contents($path . '/test.xml'); $tablesRaw = new SimpleXMLElement($xmlContent); echo '<pre>'; print_r($tablesRaw); echo '</pre>'; When I print_r I see attributes for field but attributes for acceptable-value do not show. Here is an example of the raw xml (I need the value attribute): <acceptable-value value="0"> Unknown </acceptable-value>

PHP SimpleXML get innerXML

你。 提交于 2020-01-08 13:24:19
问题 I need to get the HTML contents of answer in this bit of XML: <qa> <question>Who are you?</question> <answer>Who who, <strong>who who</strong>, <em>me</em></answer> </qa> So I want to get the string "Who who, <strong>who who</strong>, <em>me</em>". If I have the answer as a SimpleXMLElement , I can call asXML() to get "<answer>Who who, <strong>who who</strong>, <em>me</em></answer>", but how to get the inner XML of an element without the element itself wrapped around it? I'd prefer ways that

PHP SimpleXML - Remove xpath node

蹲街弑〆低调 提交于 2020-01-08 12:31:45
问题 I'm a little confused as to how i can delete a parent node of something which i can find via an xpath search: $xml = simplexml_load_file($filename); $data = $xml->xpath('//items/info[item_id="' . $item_id . '"]'); $parent = $data[0]->xpath("parent::*"); unset($parent); So, it finds the item id, no problems there - but the unset isnt getting rid of this <items> node. All i want to do is remove the <items>...</items> for this product. Obviously, there are loads of <items> nodes in the xml file

PHP SimpleXML - Remove xpath node

核能气质少年 提交于 2020-01-08 12:29:31
问题 I'm a little confused as to how i can delete a parent node of something which i can find via an xpath search: $xml = simplexml_load_file($filename); $data = $xml->xpath('//items/info[item_id="' . $item_id . '"]'); $parent = $data[0]->xpath("parent::*"); unset($parent); So, it finds the item id, no problems there - but the unset isnt getting rid of this <items> node. All i want to do is remove the <items>...</items> for this product. Obviously, there are loads of <items> nodes in the xml file

Reading Child Nodes with XMLReader

耗尽温柔 提交于 2020-01-07 05:46:28
问题 I'm trying to write an XMLReader/SimpleXML hybrid function to read a very large (700MB) XML file. The XML is in this format: <Items> <Item> <ItemKey>ABCDEF123</ItemKey> <Name> <English>An Item Name</English> <German>An Item Name In German</German> <French>An Item Name In French</French> </Name> <Description> <English>An Item Description</English> <German>An Item Description In German</German> <French>An Item Description In French</French> </Description> </Item> <Item> <ItemKey>GHIJKL456<

Xpath Regex in PHP not working

风格不统一 提交于 2020-01-06 19:44:10
问题 Here is my XML that is returned: <?xml version="1.0" encoding="utf-8"?> <lists> <list> <id>6791</id> <title><![CDATA[List 1]]></title> <type>0</type> <priority>0</priority> <due><![CDATA[0000-00-00 00:00:00]]></due> <notes><![CDATA[]]></notes> <user_id>49211</user_id> <owner><![CDATA[]]></owner> <item1> <done>0</done> <title><![CDATA[Bamboo Montage-83 Knee High Studded Contrast Colored Zipper Riding Boot - Brown PU]]></title> <barcode>B00H2Y2UY6</barcode> <priority>2</priority> <item_id>57741

Parsing XML file using php

偶尔善良 提交于 2020-01-06 15:26:28
问题 Rephrase it. Here's my code together with the XML. Everytime I try to print_r the response, It does not reflect anything. $portal = 'CaregiverPortal'; $userName = 'dxt3uyk27U3wRRrzaFGiwQ=='; $password = 'wD81PILmPuJX2fyFek937A=='; $url = "https://webapp.healthcaresynergy.com:8002/demoalpha/CaregiverPortalMobile/CaregiverPortalS ervice.svc?singleWsdl"; $option = array('trace' => 1 ); $xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'. '<soapenv:Header/>'. '

SimpleXML addChild issue when header sent

烈酒焚心 提交于 2020-01-06 15:14:18
问题 I have this code : $xml = new SimpleXMLElement('<myxml></myxml>'); $xml->addChild('testNode attr="test Attribute"'); $node = $xml->addChild('erroNode attr="My Child node causes error -> expect >"'); //$node->addChild('nodeChild attr="node Child"'); header('Content-type: text/xml'); echo $xml->asXML(); exit(); I can create a childnode with attributes via $xml , but not with $node (child's child), Why? i get the error error on line 2 at column 66: expected '>' From the docs it say that the

XMLReader & simpleXML Combo, with Conditions

两盒软妹~` 提交于 2020-01-06 14:15:58
问题 I am using a combination of XMLReader and simpleXML to parse the Posts in a WordPress export file. I realize this is a little out of the norm but, its more of backup project, so we can easily pull up one of these articles if we need it in the futre. The WP site that they were on needs to come down. The issue I am having is that some of the nodes in the XML file are empty or contain useless values (ie. Not full posts). I need to add some string length conditions but, I'm not sure how to check