simplexml

PHP - SimpleXML not returning object

时光怂恿深爱的人放手 提交于 2019-12-02 01:08:11
问题 I'm pretty stuck here on getting SimpleXML to return an object when I parse it a string that's part of an objects array. $a = '<?xml version="1.0" encoding="ISO-8859-1"?><BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId xmlns="">1145869290</sessionId><command echo="" xsi:type="UserCallForwardingAlwaysGetResponse" xmlns=""><isActive>false</isActive><forwardToPhoneNumber>43</forwardToPhoneNumber><isRingSplashActive>false<

How to save an XML file on the web server using PHP?

橙三吉。 提交于 2019-12-02 00:51:35
I am a beginner in PHP and I know nothing about XML manipulation. I am working on a Google CSE annotation XML shown below: <?xml version="1.0" encoding="UTF-8" ?> - <Annotations> - <Annotation about="http://sanspace.in/"> <Label name="_cse_byxamvbyjpc" /> </Annotation> - <Annotation about="http://blog.sanspace.in/"> <Label name="_cse_byxamvbyjpc" /> </Annotation> - <Annotation about="http://google.com/"> <Label name="_cse_exclude_byxamvbyjpc" /> </Annotation> </Annotations> I want achieve this from the above shown file: <?xml version="1.0" encoding="UTF-8" ?> - <Annotations> - <Annotation

SimpleXML, please do not expand entities [closed]

旧时模样 提交于 2019-12-02 00:30:40
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I'm using SimpleXML to try to parse a large XML file with <!ENTITY declarations. Unfortunately, SimpleXML seems too eager to go ahead and expand those entities, and I'd rather it didn't, since the entity symbols are short, easily parseable, and theoretically won't change in newer versions of the

Simple math with decimals in PHP

萝らか妹 提交于 2019-12-02 00:30:30
This is killing me! I've never had so much trouble and I can't figure out what I'm doing wrong here. If I have a number, say 2.32, and I want to do math with it it won't work out. The very simplest example: $income = $commission; //Commission is 2.32, retrieved from XML echo "income: $income<br>"; $income100 = $income*100; echo "income100: $income100<br>"; The result I get is: income: 2.32 income100: 200 How can I use a decimal number accurately with math without it changing it? Thanks so much! You need to assign $income in the following manner to get rid of the underlying SimpleXMLElement :

Accessing nth element of XML in PHP with SimpleXml

余生颓废 提交于 2019-12-01 23:29:24
问题 I have an xml formatted like this: <?xml version="1.0"?> <root> <foo id="1"> <bar>text</bar> </foo> <foo id="2"> <bar>text2</bar> </foo> </root> I know that, in PHP, you I can access the nth element of an xml file loaded with SimpleXML like so: $xml = simplexml_load_file('file.xml'); echo $xml->foo[2]->bar; but I need to access an element by a variable pulled from $_GET , so: echo $xml->foo[$var]->bar; This doesn't seem to work, and I'd really appreciate any advice. Thanks! 回答1: It seems

Modify ![CDATA[]] in PHP? (XML)

六月ゝ 毕业季﹏ 提交于 2019-12-01 22:52:45
I have an XML file which contains ![CDATA[]] data. Like this: <link><![CDATA[https://google.de]]></link> Now I heard that I can not modify ![CDATA[]] data or that they contains some special characters. But I do not remember anymore... That's the reason why I'am asking here. Can I change the values in ![CDATA[]] and if yes, how? I just want to append something like "?=dadc" on the link. Edit: My XML file structure (Want to edit the url): <?xml version="1.0" encoding="UTF-8"?> <rss> <channel xmlns:g="http://base.google.com/ns/1.0" version="2.0"> <title>Google Eur English 1</title> <description/>

PHP SimpleXML large file no extra memory usage

旧巷老猫 提交于 2019-12-01 22:29:34
In every article about SimpleXML performance and memory usage it is mentioned that all parsed content is stored in memory and that processing large files will lead to large memory usage. But recently I found that processing large files with SimpleXML do not cause large memory usage even more it causes almost none memory usage. There is my test script: <?php error_reporting(E_ALL); ini_set("display_errors", 1); print "OS: " . php_uname() . "\n"; print "PHP version: " . phpversion() . "\n"; print round(memory_get_usage() / 1024 / 1024, 2) . " Mb\n"; $large_xml = '<?xml version="1.0" encoding=

SimpleXML, please do not expand entities [closed]

假如想象 提交于 2019-12-01 22:26:39
I'm using SimpleXML to try to parse a large XML file with <!ENTITY declarations. Unfortunately, SimpleXML seems too eager to go ahead and expand those entities, and I'd rather it didn't, since the entity symbols are short, easily parseable, and theoretically won't change in newer versions of the file, while the expanded entities are English sentences that may change. Is there any way to tell SimpleXML to knock it off? I've thought of "pre-parsing" the XML file to strip out the <!ENTITY bits before passing the file contents to the XML parser, but that feels hacky, and since it's a huge file, I

Accessing nth element of XML in PHP with SimpleXml

最后都变了- 提交于 2019-12-01 22:18:08
I have an xml formatted like this: <?xml version="1.0"?> <root> <foo id="1"> <bar>text</bar> </foo> <foo id="2"> <bar>text2</bar> </foo> </root> I know that, in PHP, you I can access the nth element of an xml file loaded with SimpleXML like so: $xml = simplexml_load_file('file.xml'); echo $xml->foo[2]->bar; but I need to access an element by a variable pulled from $_GET , so: echo $xml->foo[$var]->bar; This doesn't seem to work, and I'd really appreciate any advice. Thanks! It seems SimpleXML distinguishes between numeric and non-numeric array offsets in a slightly different way to a normal

PHP read decimal integers from xml attributes

主宰稳场 提交于 2019-12-01 22:09:44
问题 Using PHP, I would like to write a function that takes numbers from XML, and multiplies those numbers. However, I don't know how to work with decimal numbers in SimpleXML. PHP $xml = new SimpleXMLElement( '<DOM> <TAB id="ID1" width="30.1" height="0.5" ></TAB> <TAB id="ID2" width="15.7" height="1.8" ></TAB> </DOM>'); foreach ($xml->children() as $second_level) { echo $second_level->attributes()->id."<br>"; echo ($second_level->attributes()->width * 10)."<br>"; echo ($second_level->attributes()