Guest User

Untitled

a guest
Aug 10th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Parsing only part of a document with expat in PHP
  2. <xmlroot>
  3. <page id="home">
  4. <h1>An HTML Header Tag!</h1>
  5. <p>This is a paragraph</p>
  6. </page>
  7. [...etc]
  8. </xmlroot>
  9.  
  10. <?php
  11.  
  12. $doc = new DOMDocument('1.0');
  13.  
  14. $root = $doc->createElement('html');
  15. $root = $doc->appendChild($root);
  16.  
  17. $head = $doc->createElement('head');
  18. $head = $root->appendChild($head);
  19.  
  20. $title = $doc->createElement('title');
  21. $title = $head->appendChild($title);
  22.  
  23. $text = $doc->createTextNode('< This is the title >');
  24. $text = $title->appendChild($text);
  25.  
  26. echo $head->ownerDocument->saveXML($head);
  27.  
  28. <xmlroot>
  29. <page id="home">
  30. <![CDATA[
  31. <h1>An HTML Header Tag!</h1>
  32. <p>This is a paragraph</p>
  33. ]]>
  34. </page>
  35. [...etc]
  36. </xmlroot>
Add Comment
Please, Sign In to add comment