Leaked source code of windows server 2003
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.

322 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. vs_xml.hxx
  5. Abstract:
  6. Declaration of XML wrapper classes
  7. Adi Oltean [aoltean] 11/17/1999
  8. TBD:
  9. Add comments.
  10. Revision History:
  11. Name Date Comments
  12. aoltean 11/17/1999 Created
  13. brianb 03/13/2000 Added XML support for Backup Extensions
  14. --*/
  15. #ifndef __VSS_XML_HXX__
  16. #define __VSS_XML_HXX__
  17. #if _MSC_VER > 1000
  18. #pragma once
  19. #endif
  20. ////////////////////////////////////////////////////////////////////////
  21. // Standard foo for file name aliasing. This code block must be after
  22. // all includes of VSS header files.
  23. //
  24. #ifdef VSS_FILE_ALIAS
  25. #undef VSS_FILE_ALIAS
  26. #endif
  27. #define VSS_FILE_ALIAS "INCXMLH"
  28. //
  29. ////////////////////////////////////////////////////////////////////////
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Forward declarations
  32. class CXMLDocument;
  33. class CXMLNode;
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CXMLNode
  36. class CXMLNode
  37. {
  38. // Constructors& destructors
  39. public:
  40. // null constructor
  41. CXMLNode();
  42. // constructor wher toplevel document node is passed in
  43. CXMLNode(const CXMLNode& node):
  44. m_pDoc(node.m_pDoc), m_pNode(node.m_pNode) {};
  45. // constructor where both node and document are passed in
  46. CXMLNode(IXMLDOMNode* pNode, IXMLDOMDocument* pDoc):
  47. m_pDoc(pDoc), m_pNode(pNode) {};
  48. // Attributes
  49. public:
  50. bool IsEmpty() const { return (m_pNode == NULL); };
  51. // Methods
  52. public:
  53. // insert a node under another node
  54. IXMLDOMNode* InsertChild
  55. (
  56. IN IXMLDOMNode* pChildNode,
  57. IN const CComVariant& vAfter = CComVariant()
  58. ) throw(HRESULT);
  59. // append a node after a particular child node
  60. void AppendChild
  61. (
  62. IN CXMLNode& childNode,
  63. OUT IXMLDOMNode** ppNewChildNode = NULL
  64. ) throw(HRESULT);
  65. // set an attribute to a GUID value
  66. void SetAttribute
  67. (
  68. IN LPCWSTR wszAttributeName,
  69. IN GUID ValueId
  70. ) throw(HRESULT);
  71. // set an attribute to a string value
  72. void SetAttribute
  73. (
  74. IN LPCWSTR wszAttributeName,
  75. IN LPCWSTR wszValue
  76. ) throw(HRESULT);
  77. // set an attribute to an integer value
  78. void SetAttribute
  79. (
  80. IN LPCWSTR wszAttributeName,
  81. IN INT nValue
  82. ) throw(HRESULT);
  83. // set an attribute to a DWORDLONG value
  84. void SetAttribute
  85. (
  86. IN LPCWSTR wszAttributeName,
  87. IN LONGLONG llValue
  88. ) throw(HRESULT);
  89. // set the text value of a node
  90. void SetValue
  91. (
  92. IN LPCWSTR wszValue
  93. ) throw(HRESULT);
  94. // add text to a node
  95. void AddText
  96. (
  97. IN LPCWSTR wszText
  98. );
  99. IXMLDOMNode *GetNodeInterface()
  100. {
  101. return m_pNode;
  102. }
  103. // save the node as an XML string
  104. BSTR SaveAsXML() throw(HRESULT);
  105. // insert a node as a child of the current node
  106. CXMLNode InsertNode
  107. (
  108. CXMLNode &node
  109. ) throw(HRESULT);
  110. // Data members
  111. protected:
  112. // toplevel document
  113. CComPtr<IXMLDOMDocument> m_pDoc;
  114. // node
  115. CComPtr<IXMLDOMNode> m_pNode;
  116. };
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CXMLDocument
  119. class CXMLDocument: public CXMLNode
  120. {
  121. private:
  122. // node currently positioned on
  123. CComPtr<IXMLDOMNode> m_pNodeCur;
  124. // attribute map for node currently positioned on
  125. CComPtr<IXMLDOMNamedNodeMap> m_pAttributeMap;
  126. // level from root (0)
  127. unsigned m_level;
  128. // Constructors& destructors
  129. public:
  130. // constructor where toplevel document node is passed in
  131. CXMLDocument(IXMLDOMDocument* pDoc = NULL):
  132. m_pNodeCur(pDoc),
  133. m_pAttributeMap(NULL),
  134. CXMLNode(pDoc, pDoc),
  135. m_level(0)
  136. {
  137. }
  138. // constructor where both toplevel node and toplevel document
  139. // are passed in
  140. CXMLDocument(IXMLDOMNode *pNode, IXMLDOMDocument *pDoc) :
  141. m_pNodeCur(pNode),
  142. m_level(0),
  143. m_pAttributeMap(NULL),
  144. CXMLNode(pNode, pDoc)
  145. {
  146. }
  147. // copy constructor
  148. CXMLDocument(const CXMLDocument& doc):
  149. CXMLNode(doc),
  150. m_pNodeCur(doc.m_pNodeCur),
  151. m_level(doc.m_level)
  152. {
  153. }
  154. // convert a node into a document
  155. CXMLDocument(const CXMLNode& node) :
  156. CXMLNode(node),
  157. m_level(0)
  158. {
  159. m_pNodeCur = m_pNode;
  160. }
  161. // Methods
  162. public:
  163. // return interface to toplevel document
  164. IXMLDOMDocument* GetInterface() const { return m_pDoc; };
  165. // set toplevel node to be the current node
  166. void SetToplevel()
  167. {
  168. m_level = 0;
  169. m_pNode = m_pNodeCur;
  170. }
  171. // set a particular node as the toplevel node in the document
  172. void SetToplevelNode(CXMLNode &node)
  173. {
  174. m_level = 0;
  175. m_pNode = node.GetNodeInterface();
  176. m_pNodeCur = m_pNode;
  177. }
  178. // initialize the document
  179. void Initialize() throw(HRESULT);
  180. // create a node within the document
  181. CXMLNode CreateNode
  182. (
  183. IN LPCWSTR wszName,
  184. IN DOMNodeType nType = NODE_ELEMENT
  185. ) throw(HRESULT);
  186. // reset current position to toplevel node
  187. void ResetToDocument
  188. (
  189. );
  190. // reset position to the parent node
  191. void ResetToParent
  192. (
  193. ) throw(HRESULT);
  194. // move to next node within the document
  195. bool Next
  196. (
  197. IN bool fDescend = TRUE,
  198. IN bool fAscendAllowed = TRUE
  199. ) throw(HRESULT);
  200. // find a particular attribute of the current node
  201. bool FindAttribute
  202. (
  203. IN LPCWSTR wszAttrName,
  204. OUT BSTR *pbstrAttrValue
  205. ) throw(HRESULT);
  206. // position to the next attribute in the current node
  207. IXMLDOMNode *NextAttribute
  208. (
  209. );
  210. // find a particular sibling or child element
  211. bool FindElement
  212. (
  213. IN LPCWSTR wsz,
  214. IN bool bGotoChild
  215. );
  216. // load the document from an XML string
  217. bool LoadFromXML
  218. (
  219. IN BSTR bstrXML
  220. ) throw(HRESULT);
  221. // load the document from a file (currently only
  222. // used for testing purposes)
  223. bool LoadFromFile
  224. (
  225. IN LPCWSTR wszFile
  226. ) throw(HRESULT);
  227. // return the curernt node
  228. inline IXMLDOMNode *GetCurrentNode()
  229. {
  230. return m_pNodeCur;
  231. }
  232. inline SetCurrentNode(IXMLDOMNode *pNode)
  233. {
  234. m_pNodeCur = pNode;
  235. }
  236. // return the current level from the toplevel node
  237. inline unsigned GetLevel() { return m_level; }
  238. private:
  239. // is the node an element with a specific element type
  240. bool IsNodeMatch
  241. (
  242. LPCWSTR wszElementType
  243. );
  244. };
  245. #endif // __VSS_XML_HXX__