xmltest.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Purely doxygen documentation
  2. // What follows is the docs for the examples.
  3. // I'd like the docs to be just before the
  4. // actual examples in xmltest.cpp, but I
  5. // can't seem to get doxygen to do that. It
  6. // would be a wonderful patch if anyone figures
  7. // it out.
  8. /** @page Example-1 Load an XML File
  9. * @dontinclude ./xmltest.cpp
  10. * Basic XML file loading.
  11. * The basic syntax to load an XML file from
  12. * disk and check for an error. (ErrorID()
  13. * will return 0 for no error.)
  14. * @skip example_1()
  15. * @until }
  16. */
  17. /** @page Example-2 Parse an XML from char buffer
  18. * @dontinclude ./xmltest.cpp
  19. * Basic XML string parsing.
  20. * The basic syntax to parse an XML for
  21. * a char* and check for an error. (ErrorID()
  22. * will return 0 for no error.)
  23. * @skip example_2()
  24. * @until }
  25. */
  26. /** @page Example-3 Get information out of XML
  27. @dontinclude ./xmltest.cpp
  28. In this example, we navigate a simple XML
  29. file, and read some interesting text. Note
  30. that this is examlpe doesn't use error
  31. checking; working code should check for null
  32. pointers when walking an XML tree, or use
  33. XMLHandle.
  34. (The XML is an excerpt from "dream.xml").
  35. @skip example_3
  36. @until </PLAY>";
  37. The structure of the XML file is:
  38. <ul>
  39. <li>(declaration)</li>
  40. <li>(dtd stuff)</li>
  41. <li>Element "PLAY"</li>
  42. <ul>
  43. <li>Element "TITLE"</li>
  44. <ul>
  45. <li>Text "A Midsummer Night's Dream"</li>
  46. </ul>
  47. </ul>
  48. </ul>
  49. For this example, we want to print out the
  50. title of the play. The text of the title (what
  51. we want) is child of the "TITLE" element which
  52. is a child of the "PLAY" element.
  53. We want to skip the declaration and dtd, so the
  54. method FirstChildElement() is a good choice. The
  55. FirstChildElement() of the Document is the "PLAY"
  56. Element, the FirstChildElement() of the "PLAY" Element
  57. is the "TITLE" Element.
  58. @until ( "TITLE" );
  59. We can then use the convenience function GetText()
  60. to get the title of the play.
  61. @until title );
  62. Text is just another Node in the XML DOM. And in
  63. fact you should be a little cautious with it, as
  64. text nodes can contain elements.
  65. @verbatim
  66. Consider: A Midsummer Night's <b>Dream</b>
  67. @endverbatim
  68. It is more correct to actually query the Text Node
  69. if in doubt:
  70. @until title );
  71. Noting that here we use FirstChild() since we are
  72. looking for XMLText, not an element, and ToText()
  73. is a cast from a Node to a XMLText.
  74. */