simplexml

Filter XML by elements [duplicate]

[亡魂溺海] 提交于 2020-01-11 14:41:51
问题 This question already has answers here : Split foreach to pages (2 answers) Closed 6 years ago . <?php $files = glob( 'docs/*.xml' ); if ( isset( $_GET['doctype'] ) == "all" ) { foreach ( $files as $file ) { $xml = new SimpleXMLElement( $file, 0, true ); echo' <tr> <td id="'. $xml->doctype .'" name="'. $xml->doctype .'" class="mainTable">' . $xml->doctype . '</td> <td><a href="viewdoc.php?docname=' . basename( $file, '.xml' ) . '&username='. $xml->startedby .'&myname='. $_SESSION['username']

Parse XML sequentially in PHP

邮差的信 提交于 2020-01-11 12:29:50
问题 I have an XML string as follows: <?xml version="1.0" encoding="utf-8"?> <document id="0" name="RegSimple" Version="0.1"> <Description> Configuration document for simple registration of incidents. This document will contain both the fixed and the user-defined fields to show on the registration screen. </Description> <Fields> <Textbox id="1" name="IncidentID" visibility="Hidden" width="500" displayreadonly="False" /> <Comment id="200" height="10" name="c1" caption=" " /> <Header id="100" name=

PHP Remove Element from XML

泪湿孤枕 提交于 2020-01-11 12:21:16
问题 I want to remove tasks that are older than today, but I can't quite figure out how to remove elements from XML file yet. $xml_file = simplexml_load_file('file.xml'); foreach ($xml_file->task as $aTask) { if ($aTask->date < $today) { //$xml_file->removeChild($aTask); //doesnt work } } Here is my XML file below: <?xml version="1.0"?> <calender> <task><date>00/00/0000</date><title>My Birthday</title><description>Today is my birthday!</description></task><task><date>04/01/2013</date><title>ghh<

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

落爺英雄遲暮 提交于 2020-01-11 10:38:07
问题 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

Successfully parsed SimpleXMLElement comparison to 'false' returning 'true'

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-11 10:05:25
问题 I got a very awkward and specific issue with a simplexml evaluation. The code: $simplexml = simplexml_load_string($xmlstring); var_dump($simplexml); var_dump($simplexml == false); //this comparison var_dump($simplexml) returns the actual structure of my simplexml but the comparison returns 'true' for this specific simplexml, which I can't show the structure because of my contract. I'm sure that's very specifc issue 'cause I tried other XML strings and the comparison returns 'false'.

Successfully parsed SimpleXMLElement comparison to 'false' returning 'true'

耗尽温柔 提交于 2020-01-11 10:04:15
问题 I got a very awkward and specific issue with a simplexml evaluation. The code: $simplexml = simplexml_load_string($xmlstring); var_dump($simplexml); var_dump($simplexml == false); //this comparison var_dump($simplexml) returns the actual structure of my simplexml but the comparison returns 'true' for this specific simplexml, which I can't show the structure because of my contract. I'm sure that's very specifc issue 'cause I tried other XML strings and the comparison returns 'false'.

Successfully parsed SimpleXMLElement comparison to 'false' returning 'true'

你。 提交于 2020-01-11 10:03:34
问题 I got a very awkward and specific issue with a simplexml evaluation. The code: $simplexml = simplexml_load_string($xmlstring); var_dump($simplexml); var_dump($simplexml == false); //this comparison var_dump($simplexml) returns the actual structure of my simplexml but the comparison returns 'true' for this specific simplexml, which I can't show the structure because of my contract. I'm sure that's very specifc issue 'cause I tried other XML strings and the comparison returns 'false'.

php xpath retrieving attribute-values based on multiple attributes and parent-attributes

喜夏-厌秋 提交于 2020-01-11 07:16:06
问题 I need to select nodes from xml, conditions see below. I am using simplexml, so the xpath has to be 1.0. XML snippet: <scales> <scale id="1" gender="*" age="*"> <d scid="hi" raw="10" t="76" /> <d scid="pn" raw="12" t="80" /> </scale> <scale id="2" gender="m" age="*"> <d scid="hi" raw="8" t="79" /> <d scid="pn" raw="2" t="50" /> </scale> <scale id="3" gender="*" age="19-39"> <d scid="hi" raw="0" t="48" /> <d scid="pn" raw="10" t="49" /> </scale> </scales> Now, I want to select the t -Attribute

php xpath retrieving attribute-values based on multiple attributes and parent-attributes

痴心易碎 提交于 2020-01-11 07:16:03
问题 I need to select nodes from xml, conditions see below. I am using simplexml, so the xpath has to be 1.0. XML snippet: <scales> <scale id="1" gender="*" age="*"> <d scid="hi" raw="10" t="76" /> <d scid="pn" raw="12" t="80" /> </scale> <scale id="2" gender="m" age="*"> <d scid="hi" raw="8" t="79" /> <d scid="pn" raw="2" t="50" /> </scale> <scale id="3" gender="*" age="19-39"> <d scid="hi" raw="0" t="48" /> <d scid="pn" raw="10" t="49" /> </scale> </scales> Now, I want to select the t -Attribute

Is it possible to insert a comment tag into an xml using simplexml?

一曲冷凌霜 提交于 2020-01-10 04:52:10
问题 I am using SimpleXML to build a document, and wondering whether it is possible to insert comment tag to the document like this: <root> <!-- some comment --> <value> </root> EDIT : The comment is somewhere in the middle of the document. <root> <tag1 /> <!-- some comment --> <value /> </root> 回答1: Unfortunately, SimpleXML doesn't handle comments. As it's been mentionned, DOM does handle comments but it's a kind of a bother to use for simple stuff, compared to SimpleXML. My recommendation: try