You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IXMLNode.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include "defines.h"
  3. #include <string>
  4. #include <cstdlib> // fix Unix compatibility
  5. namespace XML {
  6. /**
  7. * @class IXMLNode
  8. * @author Serrière Guillaume (INRIA/Loria)
  9. * @brief Symbolize a node in a XML tree structure.
  10. * @sa XML
  11. */
  12. class XML_API IXMLNode
  13. {
  14. public:
  15. virtual void release() = 0;
  16. virtual const char* getName() const = 0;
  17. //Attribute
  18. /**
  19. * @brief Add the attribute name with value
  20. * value to the node.
  21. * @param name [in] : Name of the attribute
  22. * @param value [in] : Value of the attribute
  23. * @return true in success, false otherwise
  24. */
  25. virtual bool addAttribute(const char* name, const char* value) = 0;
  26. /**
  27. * @brief Indicate if an attribute exists or not.
  28. * @param name [in] : Name of the attribute
  29. * @return true if attribute exists, false otherwise
  30. */
  31. virtual bool hasAttribute(const char* name) const = 0;
  32. /**
  33. * @brief Return the value of an attribute.
  34. * @param name [in] : Name of the attribute
  35. * @return Value of the attribute
  36. */
  37. virtual const char* getAttribute(const char* name) const = 0;
  38. //PCDATA
  39. /**
  40. * @brief Set the PCDATA of the node.
  41. * @param data [in] : Value of the PCDATA
  42. */
  43. virtual void setPCData(const char* data) = 0;
  44. /**
  45. * @brief Apppend a string to the current PCDATA of the node
  46. * @param data [in] : Value of teh PCDATA to append
  47. */
  48. virtual void appendPCData(const char* data) = 0;
  49. /**
  50. * @brief Return the PCDATA of the node.
  51. * @return Value of PCDATA
  52. */
  53. virtual const char* getPCData() const = 0;
  54. //Child
  55. /**
  56. * @brief Add a node child of the
  57. * @param node [in] : The Node that will became the new child
  58. */
  59. virtual void addChild(IXMLNode* node) = 0;
  60. /**
  61. * @brief Return the ith child of the node.
  62. * @param index [in] : index of the child.
  63. * @return The ith child of the node.
  64. */
  65. virtual IXMLNode* getChild(const size_t index) const = 0;
  66. /**
  67. * @brief Return the first child with the name name.
  68. * @param name [in]] : Name of th child
  69. * @return The first child of the node which name is name.
  70. */
  71. virtual IXMLNode* getChildByName(const char* name) const = 0;
  72. /**
  73. * @brief Return the amount of child the node has.
  74. * @return Amount of child.
  75. */
  76. virtual size_t getChildCount() const = 0;
  77. //XML generation
  78. /**
  79. * @brief Return a string which contains the XML of the node. The string is dynamically instantiate so
  80. * it requires to be free.
  81. * @param depth [in] : Amount of indentation
  82. * @return XML string describing the node and its childs.
  83. */
  84. virtual char* getXML(const size_t depth = 0) const = 0;
  85. protected:
  86. virtual ~IXMLNode() {}
  87. };
  88. /**
  89. * @brief Create a new node with the name name. The node is created dynamically and requires to be free.
  90. * @param name [in] : Name of the node
  91. * @return New node
  92. */
  93. extern XML_API IXMLNode* createNode(const char* name);
  94. } // namespace XML