simplexml

Filter XML by elements [duplicate]

好久不见. 提交于 2019-12-02 13:14:54
This question already has an answer here: Split foreach to pages 2 answers <?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'] .'">' . basename( $file, '.xml' ) . '</a></td> <td><a href="viewprofile.php?name='. $xml->startedby .'">'. $xml->startedby .'

Problems getting XML content via https using SimpleXML and PHP [duplicate]

房东的猫 提交于 2019-12-02 13:10:55
Possible Duplicate: How to enable HTTPS stream wrappers I'm using simple XML to get content from an API. Usually I have no problems but now the URL is HTTPS it doesn't seem to work. Is there anyway around this? Example XML (url): <?xml version="1.0"?> <calendars> <calendar accommodation_id="1049165"> <day date="2012-08-09" vacancy="false" minimum_nights="7" arrival_day="true"/> <day date="2012-08-10" vacancy="false" minimum_nights="3" arrival_day="true"/> <day date="2012-08-11" vacancy="false" minimum_nights="3" arrival_day="true"/> <!-- ... --> <day date="2014-01-31" vacancy="true" minimum

simplexml_load_file with & (ampersand) in url with Solr

风流意气都作罢 提交于 2019-12-02 13:04:27
问题 I am using Solr and have the following query which works fine from my browser: http://www.someipaddress.com:8983/solr/select?q=*&fq=shopid:40&start=0&rows=18&fq=manufacturer:"Bausch+%26+Lomb" In part of the return xml I see: <str>manufacturer:"Bausch & Lomb"</str> However when I try and get the above url using simplexml_load_file like this: $xml = simplexml_load_file("http://127.0.0.1:8983/solr/select?q=*&fq=shopid:40&start=0&rows=18&fq=manufacturer:\"Bausch+%26+Lomb\""); I get no results

SimpleXMLElement file does not load xmlString

我与影子孤独终老i 提交于 2019-12-02 12:26:34
I am trying to work on an XML Based problem. So far, it's proving to be a bummer for some reason. My code is only two lines and for some reason nothing is loading in. The code: $xmlString = file_get_contents('file.xml'); $xmlObject = simplexml_load_string($xmlString); // also in the above line I have tried // 1. new SimpleXMLElement('file.xml') // 2. simplexml_load_file('file.xml') The functions do not load, and this I can tell by var_dumping $xmlObject, which returns boolean false. file_get_contents does load the string $xmlString and var_dumping it returns the string, so location of the file

DOM with SimpleXML Doesnt show the data in XML format in Browser using PHP

白昼怎懂夜的黑 提交于 2019-12-02 11:41:57
This is my PHP code to read XML from a URL using SimpleXML and DOM to change some parameters and show it on a web page The Feed i am reading is at http://tinyurl.com/boy7mr5 <?php $xml = simplexml_load_file('http://www.abc.com'); $doc = new DOMDocument(); $doc->formatOutput = true; $r = $doc->createElement( "All_Products" ); $doc->appendChild( $r ); foreach( $xml as $Product) { $b = $doc->createElement( "Product" ); $doc->appendChild( $b ); foreach($Product as $prname=>$value) { $prname1 = $doc->createElement( $prname ); $prname1->appendChild( $doc->createTextNode( $value ) ); $b->appendChild(

How to traverse SimpleXML to edit text nodes?

我是研究僧i 提交于 2019-12-02 11:19:17
I need to implement the following algorithm with SimpleXML: put a XML fragment string into a SimpleXML object; traverse all the nodes, selecting text nodes; edit the text node (example convert to upper case); return the xml as string. PROBLEMS: How to load a XML with named entities (ex.   ). To traverse XML to get only text nodes... With $sx->xpath('//text()'); I can not edit the nodes, how to select text nodes to edition? You can override the text content of a node returned by a SimpleXML XPath query by assigning to $node[0] , e.g. foreach ( $sx->xpath('//text()') as $text_node ) { $text_node

How can I display XML with whitespace formatting?

折月煮酒 提交于 2019-12-02 10:56:09
问题 I have a web page that builds an XML from an existing XML applying changes. I want to output the new XML file in a textarea as a preview. It displays any nodes that were present in the original XML with the proper whitespaces/formatting (indents and linebreaks) that the original XML had just fine, but any new nodes are all displayed on one line with no indents. Example: <original parent node> <original child>value</original child> </original parent node> <original parent node> <new child

PHP simplexml xpath search for value in an ELEMENT containing tab delimited text?

烈酒焚心 提交于 2019-12-02 10:34:10
How to do a PHP simplexml xpath search for text value in a tab delimited ELEMENT and returning text from that same element at a different offset from where the search text offset? Lets say I wish to find the DATA element containing a Value of '2' and return the LongValue 'Academy'. The xml document is in the following format <METADATA Resource="Property" Lookup="Area"> <COLUMNS>->fieldname *(->fieldname)-></COLUMNS> *(<DATA>->fielddata *(->fielddata)-></DATA>) </METADATA> Note: ignore spaces *() means 1 or more -> is tab chr(9) In the example below the COLUMNS element contains three column

SimpleXML Dynamic element names

两盒软妹~` 提交于 2019-12-02 09:56:17
问题 echo $xml->SLOT1->Effect; echo $xml->SLOT2->Effect; echo $xml->SLOT3->Effect; Is there a way to simplify this by using a for loop? I tried this but it echos nothing: for ($x = 1; $x <= 3; $x++) { echo $xml->SLOT[$x]->Effect; } 回答1: You can use $xml->{"SLOT".$x}->Effect; 回答2: for ($x = 1; $x <= 3; $x++) { echo $xml->{SLOT.$x}->Effect; } 来源: https://stackoverflow.com/questions/10662795/simplexml-dynamic-element-names

php: export array to xml trouble

旧巷老猫 提交于 2019-12-02 09:40:16
I have an array which I need to convert to XML with SimpleXML. The method below is almost doing the work but there's one trouble with it. It can't generate structure like this: $xmlFields = array( 'rootElt' => array( 'field1' => '', 'field2' => '', 'field3' => array( 'field4' => array( 'income' => array( 'owner' => '', 'description' => '', ), 'income' => array( 'owner' => '', 'description' => '', ), ), ) ) ); It writes only the last 'income' of section 'field4' but I need the output like: <field4> <income> <owner>....</owner> <description>....</description> </income> <income> <owner>....<