simplexml

Selecting attribute values based on another attribute value with SimpleXML [duplicate]

安稳与你 提交于 2019-12-11 02:12:59
问题 This question already has answers here : SimpleXML: Selecting Elements Which Have A Certain Attribute Value (2 answers) Closed 6 years ago . I'm trying to display an image using an xml file and SimpleXML The XML code is <icons> <icon size="tiny" href="/FF02-tiny.jpg" /> <icon size="sidebar" href="/FF02-sidebar.jpg" /> <icon size="full" href="/FF02-full.jpg" /> </icons> I want to get the href attribute for the size="full" line. I've tried icons->icon->attributes()->href but this just gives me

Using addChild with an index position

偶尔善良 提交于 2019-12-11 02:12:17
问题 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" /> </Menu> </Test>'; $_RenderedXML = new SimpleXMLElement($_XML); //Add a new Link node $_NewLink = $_RenderedXML->Menu->addChild("Link"); $_NewLink->addAttribute("href", "page3.htm"); echo $_RenderedXML->asXML(); ?> This will render the XML with the new node below it's sibbling. I would

How to parse SimpleXMLElement in php / Laravel 5?

梦想与她 提交于 2019-12-11 01:44:21
问题 I use Guzzle to make an XML request to an external API in the back-end. This is where I create the Guzzle client: $client = new Client(); //GuzzleHttp\Client This is where I make the request: $request = $client->request( 'GET', 'This is where I put the URL'); This is where I get the Guzzle response and try to parse it: $xml = $request->getBody()->getContents(); $xml = new \SimpleXMLElement($xml); $xml = simplexml_load_string($xml); If I do this: dd($xml); I receive this in return:

Help accessing xml attribute in php [duplicate]

亡梦爱人 提交于 2019-12-11 01:11:20
问题 This question already has answers here : SimpleXML: Selecting Elements Which Have A Certain Attribute Value (2 answers) Closed 6 years ago . I'm new to php and coding in general. I'm trying to parse xml from a remote device and access specific value data. I would like to display group 9 probe 1 value for example and I cannot get it to work. Any tips? Here is the xml: <?xml version="1.0" encoding="ISO-8859-1" ?> - <Device id="S10011" hb="1935"> <Group id="1" /> <Group id="2" /> <Group id="3" /

PHP: preg_match() not correct

天涯浪子 提交于 2019-12-11 00:09:33
问题 I have the following string: <w:pPr> <w:spacing w:line="240" w:lineRule="exact"/> <w:ind w:left="1890" w:firstLine="360"/> <w:rPr> <w:b/> <w:color w:val="00000A"/> <w:sz w:val="24"/> </w:rPr> </w:pPr> and I am trying to parse the "w:sz w:val" value using preg_match(). So far, I've tried: preg_match('/<w:sz w:val="(\d)"/', $p, $fonts); but this has not worked, and I'm unsure why? Any Ideas? Thank you in advance! 回答1: You were trying to capture only single-digit numbers. Try adding a + to make

PHP + XML - how to rename and delete XML elements using SimpleXML or DOMDocument?

梦想与她 提交于 2019-12-10 23:55:39
问题 I've had some success due to the help of StackOverflow community to modify a complex XML source for use with jsTree. However now that I have data that is usable, it is only so if i manually edit the XML to do the following : Rename all <user> tags to <item> Remove some elements before the first <user> tag insert an 'encoding=UTF-8' into the XML opener and lastly modify the <response> (opening XML tag) to <root> XML File Example : SampleXML I have read and read through so many pages on here

How to change attribute on a simpleXML element?

女生的网名这么多〃 提交于 2019-12-10 21:44:09
问题 I parsed a XML file with SimepleXML: <element data="abc,def"> EL </element> But now I want to append something to the "data" attribute. Not in the file, but in my variables (in the object structure that I got from simplexml_load_file). How can I do that? 回答1: Untested, but should work: $element->attributes()->data = ((string) $element->attributes()->data) . ',ghi'; 回答2: Well, it can be done like $element['data'] .= ',ghi'; 回答3: Use this corrected.... class ExSimpleXMLElement extends

PHP simplexml Entities

删除回忆录丶 提交于 2019-12-10 20:58:24
问题 What's going one here? $string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <album> <img src="002.jpg" caption="wássup?" /> </album> XML; $xml = simplexml_load_string($string); // $xmlobj = simplexml_load_file("xml.xml"); // same thing echo "<pre>"; var_dump($xml); echo "</pre>"; Error: Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Entity 'aacute' not defined 回答1: &aacute is not an XML entity - you're thinking about HTML. Special

simplexml, returning multiple items with the same tag

与世无争的帅哥 提交于 2019-12-10 20:38:17
问题 I have the following XML file loaded into php simplexml. <adf> <prospect> <customer> <name part="first">Bob</name> <name part="last">Smith</name> </customer> </prospect> </adf> using $customers = new SimpleXMLElement($xmlstring); This will return "Bob" but how do I return the last name? echo $customers->prospect[0]->customer->contact->name; 回答1: You can access the different <name> elements by number, using array-style syntax. $names = $customers->prospect[0]->customer->name; echo $names[0]; /

SimpleXML get Element Content between Child Elements

懵懂的女人 提交于 2019-12-10 20:31:51
问题 I am parsing XML in PHP with SimpleXML and have an XML like this: <xml> <element> textpart1 <subelement>subcontent1</subelement> textpart2 <subelement>subcontent2</subelement> textpart3 </element> </xml> When I do $xml->element it naturally gives me the whole element, as in all three textparts. So if I parse this into an array (with a foreach for the children) I get: 0 => textpart1textpart2textpart3, 1 => subcontent1, 2 => subcontent2 I need a way to parse the <element> node so that each