XML DOM Document

From Code Trash

Jump to: navigation, search

Contents

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

Untitled Document

  1. PHP: DOM - Manual

    <?php class extDOMDocument extends DOMDocument { public function createElement($name, $value=null) ...... function.dom-domdocument-getelementsbytagname.php ...
    php.net/manual/en/book.dom.php - Cached - Similar
  2. PHP: DOMDocument - Manual

    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 - Cached
  3. PHP XML DOM

    <?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeName . ...
    www.w3schools.com/php/php_xml_dom.asp - Cached - Similar
  4. PHP: DOMDocument->save() - Manual

    29 Oct 2005 ... <?php $doc = new DOMDocument('1.0'); // we want a nice output $doc->formatOutput = true; $root = $doc->createElement('book'); ...
    www.phpbuilder.com/.../function.dom-domdocument-save.php - Cached - Similar
  5. PHP DomDocument Tutorial | PHP for everyone

    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.
    php4every1.com/tutorials/php-domdocument-tutorial/ - Cached
  6. Modifying Templates Using DOMDocument In PHP | UltraMega Blog

    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.
    www.ultramegatech.com/.../modifying-templates-using-domdocument-in-php/ - Cached - Similar
  7. PHP DOMDocument stripping HTML tags - Stack Overflow

    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, ...
    stackoverflow.com/.../php-domdocument-stripping-html-tags - Cached - Similar
  8. PHP-5 DomDocument: Creating a Basic XML | Abdullah Rubiyath ...

    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 ...
    www.itsalif.info/.../php-5-domdocument-creating-basic-xml - Cached - Similar
  9. PHP DomDocument Tutorial - Tutorialized

    1 post - 1 author - Last post: 2 Dec 2009
    PHP DomDocument Tutorial- PHP. Visit Tutorialized to discuss PHP DomDocument Tutorial.
    forums.tutorialized.com/php.../php-domdocument-tutorial-197421.html - Cached
  10. XML Parsing with PHP DOMDocument :: zedwood.com

    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 ...
    www.zedwood.com/.../xml-parsing-with-php-domdocument - Cached - Similar

1 2 3 4 5 6 7 8 9 10 Next

Reference

http://www.php.net/manual/en/domdocument.getelementsbytagname.php

Personal tools
Google AdSense