XML DOM Document
From Code Trash
Contents
- 1 My Example
- 2 PHP Example
- 3 Search Result
- 3.1 <a href="http://php.net/manual/en/book.dom.php" target="_blank">PHP: DOM - Manual</a>
- 3.2 <a href="http://php.net/manual/en/class.domdocument.php" target="_blank">PHP: DOMDocument - Manual</a>
- 3.3 <a href="http://www.w3schools.com/php/php_xml_dom.asp" target="_blank">PHP XML DOM</a>
- 3.4 <a href="http://www.phpbuilder.com/manual/en/function.dom-domdocument-save.php" target="_blank">PHP: DOMDocument->save() - Manual</a>
- 3.5 <a href="http://php4every1.com/tutorials/php-domdocument-tutorial/" target="_blank">PHP DomDocument Tutorial | PHP for everyone</a>
- 3.6 <a href="http://www.ultramegatech.com/blog/2009/07/modifying-templates-using-domdocument-in-php/" target="_blank">Modifying Templates Using DOMDocument In PHP | UltraMega Blog</a>
- 3.7 <a href="http://stackoverflow.com/questions/85520/php-domdocument-stripping-html-tags" target="_blank">PHP DOMDocument stripping HTML tags - Stack Overflow</a>
- 3.8 <a href="http://www.itsalif.info/content/php-5-domdocument-creating-basic-xml" target="_blank">PHP-5 DomDocument: Creating a Basic XML | Abdullah Rubiyath ...</a>
- 3.9 <a href="http://forums.tutorialized.com/php-91/php-domdocument-tutorial-197421.html" target="_blank">PHP DomDocument Tutorial - Tutorialized</a>
- 3.10 <a href="http://www.zedwood.com/article/129/xml-parsing-with-php-domdocument" target="_blank">XML Parsing with PHP DOMDocument :: zedwood.com</a>
- 4 Reference
My Example
<? $cont = file_get_contents("17242342.rss"); //echo $xml; $xml = new DOMDocument(); $xml->loadXML($cont); $x = $xml->getElementsByTagName('item'); //echo $x->length; foreach($x as $now) { $title = $now->getElementsByTagName('title')->item(0)->nodeValue; $dati = $now->getElementsByTagName('pubDate')->item(0)->nodeValue; $link = $now->getElementsByTagName('link')->item(0)->nodeValue; $title = substr($title,0, strpos($title,'http://',0)); $dati = substr($dati,0,26); ?> <?=$title?> <?=$dati?> <?=$link?> <? } ?>
PHP Example
<?php $doc = new DOMDocument(); $doc->load( 'Users.xml' ); $dataset = $doc->getElementsByTagName( "dataUser" ); foreach( $dataset as $row ) { $xmlUserNames = $row->getElementsByTagName( "UserName" ); $xmlUserName = $xmlUserNames->item(0)->nodeValue; $xmlEmails = $row->getElementsByTagName( "Email" ); $xmlEmail = $xmlEmails->item(0)->nodeValue; $xmlDisplayNames = $row->getElementsByTagName( "DisplayName" ); $xmlDisplayName = $xmlDisplayNames->item(0)->nodeValue; echo "$xmlUserName - $xmlEmail - $xmlDisplayNamen"; } ?> Contents in Users.xml <NewDataSet> <dataUser> <UserName>StudioAMK</UserName> <Email>user1@mail.com</Email> <DisplayName>StudioAMK.com</DisplayName> </dataUser> <dataUser> <UserName>User2</UserName> <Email>user2@mail.com</Email> <DisplayName>UserTwo</DisplayName> </dataUser> </NewDataSet>
Search Result
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head>
<body>
-
<a href="http://php.net/manual/en/book.dom.php" target="_blank">PHP: DOM - Manual</a>
<?php class extDOMDocument extends DOMDocument { public function createElement($name, $value=null) ...... function.dom-domdocument-getelementsbytagname.php ...
php.net/manual/en/book.dom.php - <a href="http://74.125.153.132/search?q=cache:9MkRQeWWdPUJ:php.net/manual/en/book.dom.php+php+DOMDocument&cd=1&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:php.net/manual/en/book.dom.php+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CAgQHzAA" target="_blank">Similar</a> -
<a href="http://php.net/manual/en/class.domdocument.php" target="_blank">PHP: DOMDocument - Manual</a>
Child class of DOMDocument which has a toArray() method. Enjoy and/or improve <?php class MyDOMDocument extends DOMDocument ...
php.net/manual/en/class.domdocument.php - <a href="http://74.125.153.132/search?q=cache:iL4Uyabe54gJ:php.net/manual/en/class.domdocument.php+php+DOMDocument&cd=2&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a>
<tbody>
<a href="http://www.google.co.in/search?q=php+DOMDocument&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a#" target="_blank">Show more results from php.net</a> -
<a href="http://www.w3schools.com/php/php_xml_dom.asp" target="_blank">PHP XML DOM</a>
<?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeName . ...
<a href="http://www.w3schools.com/" target="_blank">www.w3schools.com/</a>php/php_xml_dom.asp - <a href="http://74.125.153.132/search?q=cache:COIl4XUm_UsJ:www.w3schools.com/php/php_xml_dom.asp+php+DOMDocument&cd=3&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:www.w3schools.com/php/php_xml_dom.asp+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CA8QHzAC" target="_blank">Similar</a> -
<a href="http://www.phpbuilder.com/manual/en/function.dom-domdocument-save.php" target="_blank">PHP: DOMDocument->save() - Manual</a>
29 Oct 2005 ... <?php $doc = new DOMDocument('1.0'); // we want a nice output $doc->formatOutput = true; $root = $doc->createElement('book'); ...
www.php<a href="http://builder.com/.../function.dom-" target="_blank">builder.com/.../function.dom-</a>domdocument-save.php - <a href="http://74.125.153.132/search?q=cache:e7VAEF7FVrAJ:www.phpbuilder.com/manual/en/function.dom-domdocument-save.php+php+DOMDocument&cd=4&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:www.phpbuilder.com/manual/en/function.dom-domdocument-save.php+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CBIQHzAD" target="_blank">Similar</a> -
<a href="http://php4every1.com/tutorials/php-domdocument-tutorial/" target="_blank">PHP DomDocument Tutorial | PHP for everyone</a>
This will be a quick tutorial that will show you how to use PHP's DOMDocument to parse your XML so you do not have to use XML parser.
php<a href="http://4every1.com/tutorials/" target="_blank">4every1.com/tutorials/</a>php-domdocument-tutorial/ - <a href="http://74.125.153.132/search?q=cache:EWyHTgGbxpEJ:php4every1.com/tutorials/php-domdocument-tutorial/+php+DOMDocument&cd=5&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> -
<a href="http://www.ultramegatech.com/blog/2009/07/modifying-templates-using-domdocument-in-php/" target="_blank">Modifying Templates Using DOMDocument In PHP | UltraMega Blog</a>
In the previous post, Generating (X)HTML Documents Using DOMDocument In PHP, we explored the PHP DOMDocument class by generating an (X)HTML page completely.
<a href="http://www.ultramegatech.com/.../modifying-templates-using-" target="_blank">www.ultramegatech.com/.../modifying-templates-using-</a>domdocument-in-php/ - <a href="http://74.125.153.132/search?q=cache:2yVlG_5VQHYJ:www.ultramegatech.com/blog/2009/07/modifying-templates-using-domdocument-in-php/+php+DOMDocument&cd=6&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:www.ultramegatech.com/blog/2009/07/modifying-templates-using-domdocument-in-php/+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CBcQHzAF" target="_blank">Similar</a> -
<a href="http://stackoverflow.com/questions/85520/php-domdocument-stripping-html-tags" target="_blank">PHP DOMDocument stripping HTML tags - Stack Overflow</a>
I'm working on a small templating engine, and I'm using DOMDocument to parse ... Nothing: nodeValue is the concatenation of the value portion of the tree, ...
<a href="http://stackoverflow.com/.../" target="_blank">stackoverflow.com/.../</a>php-domdocument-stripping-html-tags - <a href="http://74.125.153.132/search?q=cache:lglmAooj8EIJ:stackoverflow.com/questions/85520/php-domdocument-stripping-html-tags+php+DOMDocument&cd=7&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:stackoverflow.com/questions/85520/php-domdocument-stripping-html-tags+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CBoQHzAG" target="_blank">Similar</a> -
<a href="http://www.itsalif.info/content/php-5-domdocument-creating-basic-xml" target="_blank">PHP-5 DomDocument: Creating a Basic XML | Abdullah Rubiyath ...</a>
Since I wrote my ZCE Exam in last Sept 08', I have been using DomDocument mainly to generate XML files. Its a powerful library of PHP-5, one thing I find ...
<a href="http://www.itsalif.info/.../" target="_blank">www.itsalif.info/.../</a>php-5-domdocument-creating-basic-xml - <a href="http://74.125.153.132/search?q=cache:0ttwBqXseFQJ:www.itsalif.info/content/php-5-domdocument-creating-basic-xml+php+DOMDocument&cd=8&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:www.itsalif.info/content/php-5-domdocument-creating-basic-xml+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CB0QHzAH" target="_blank">Similar</a> -
<a href="http://forums.tutorialized.com/php-91/php-domdocument-tutorial-197421.html" target="_blank">PHP DomDocument Tutorial - Tutorialized</a>
1 post - 1 author - Last post: 2 Dec 2009PHP DomDocument Tutorial- PHP. Visit Tutorialized to discuss PHP DomDocument Tutorial.
<a href="http://forums.tutorialized.com/" target="_blank">forums.tutorialized.com/</a>php.../php-domdocument-tutorial-197421.html - <a href="http://74.125.153.132/search?q=cache:KzHLy3mXMUIJ:forums.tutorialized.com/php-91/php-domdocument-tutorial-197421.html+php+DOMDocument&cd=9&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a>
-
<a href="http://www.zedwood.com/article/129/xml-parsing-with-php-domdocument" target="_blank">XML Parsing with PHP DOMDocument :: zedwood.com</a>
XML Parsing with PHP DOMDocument. PHP5 has several XML parsers built in, here is some sample code for parsing with DOM XML. It is by no means an exhaustive ...
<a href="http://www.zedwood.com/.../xml-parsing-with-" target="_blank">www.zedwood.com/.../xml-parsing-with-</a>php-domdocument - <a href="http://74.125.153.132/search?q=cache:C3XBKbI0nKMJ:www.zedwood.com/article/129/xml-parsing-with-php-domdocument+php+DOMDocument&cd=10&hl=en&ct=clnk&gl=in&client=firefox-a" target="_blank">Cached</a> - <a href="http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=bc2&q=related:www.zedwood.com/article/129/xml-parsing-with-php-domdocument+php+DOMDocument&sa=X&ei=-M9CS4WtBovW7AOdp9iIBA&ved=0CCMQHzAJ" target="_blank">Similar</a>
</body> </html>
Reference
http://www.php.net/manual/en/domdocument.getelementsbytagname.php