PHP ?? ?? ???? PHP XML DOM
1. DOM?? ??????
W3C DOM? HTML ? XML ??? ?? ?? ?? ??? ?? ??? ??? ????? ???? ?? ?? ?????? ?????.
W3C DOM? ??? ??(??, XML ? HTML)? ??? ??(DOM ?? 1/2/3)? ????.
?? DOM - ?? ??? XML DOM - XML ????? ?? ?? ?? ??? ?????.
?? ??
XML DOM? ?? ??? ????? XML DOM ????? ?????.
XML ??? ?? ??????? XML? ?????. ??. XML ???? ? ?? ?? ??? ????.
?? ?? ??: ? ??? XML ??? ?? ??? ?????. ?? ??? ???? DOM(?? ?? ??)? ?? ??? ??? ?? ???? ?????.
?? ?? ??: XML ??? ??? ???? ?????. ?? ???? ???? ??? ?? ???? ??? ?????.
DOM ??? ?? ?? ?????.
?? XML ?? ??? ??????.
<?xml version="1.0" encoding="ISO-8859-1"?> <from>Jani</from>
XML DOM ?? XML? ?? ??? ??????.
?? 1: XML ??
- ?? 2: ?? ??: <from>
?? 3: ??? ??: "Jani"
- 3. ??
DOM XML ?? ??? PHP ??? ?? ?????. ? ??? ???? ?? ??? ???? ????.
4. XML ??
? ???? ?? XML ??? ?????. <?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
5. XML ?? ? ??
XML ??? ????? XML? ??? ? ???? ???. Instance
<?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); print $xmlDoc->saveXML(); ?>
? ??? ??? ?????:
ToveJaniReminder ?? ??? ?? ?? ???!
???? ??? ?? ??? ?? ?? HTML? ? ? ????:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
?? ???? DOMDocument-Object? ???? "note.xml"? XML? ? ?? ??? ?????.
saveXML() ??? ?? XML ??? ???? ???? ??? ? ??? ???.
6. XML ??
XML ??? ????? XML? ??? ?? <note> ??: Instance
<?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeName . " = " . $item->nodeValue . "<br>"; } ?>
? ??? ??? ?????:
#text =
to = Tove
#text =
from = Jani
#text =
heading = ??
#text =
body = ?? ??? ?? ??? ?? ??????!
#text =
?? ???? ? ?? ??? ? ??? ??? ?? ?? ? ? ????.
XML? ???? ????? ?? ??? ??? ?????. XML DOM ??? ?? ?? ??? ????? ??? ???? ??? ??? ??? ? ????.