PHP Read and write xml,php read write XML
What is XML?
XML is a data storage format. It does not define what data is saved, nor does it define the format of the data. XML simply defines the tags and the attributes of those tags. Well-formed XML tags look like this:
Copy the Code code as follows:
Jack Herrington
Dom Read XML
Copy the Code code as follows:
<?php
$doc = new DOMDocument ();
$doc->load (' books.xml ');
$books = $doc->getelementsbytagname ("book");
foreach ($books as $book)
{
$authors = $book->getelementsbytagname ("author");
$author = $authors->item (0)->nodevalue;
$publishers = $book->getelementsbytagname ("publisher");
$publisher = $publishers->item (0)->nodevalue;
$titles = $book->getelementsbytagname ("title");
$title = $titles->item (0)->nodevalue;
echo "$title-$author-$publisher \ n";
}
?>
Writing XML in DOM
Copy the Code code as follows:
<?php
$books = Array ();
$books [] = Array (
' Title ' = ' PHP Hacks ',
' Author ' = ' Jack Herrington ',
);
$doc = new DOMDocument (); Creating DOM objects
$doc->formatoutput = true;
$r = $doc->createelement ("books");//Create label
$doc->appendchild ($R); Add the label to the XML format.
foreach ($books as $book)
{
$b = $doc->createelement ("book"); Create a label
$author = $doc->createelement ("author");
$author->appendchild ($doc->createtextnode ($book [' author ']); Add content to tags
$b->appendchild ($author); Add child tags to parent tag
$r->appendchild ($b); Join the Parent tab!
}
echo $doc->savexml ();
?>
The above is the 2 paragraphs read and write the DOM code of the XML, the small partners understand no, have any questions can give me a message
http://www.bkjia.com/PHPjc/914062.html www.bkjia.com true http://www.bkjia.com/PHPjc/914062.html techarticle PHP Read and write xml,php read write XML what is XML? XML is a data storage format. It does not define what data is saved, nor does it define the format of the data. XML simply defines the ...