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.

365 lines
7.0 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. // assignment operator
  49. void operator = (CXMLNode other)
  50. {
  51. m_pDoc = other.GetDocument();
  52. m_pNode = other.GetNodeInterface();
  53. }
  54. // Attributes
  55. public:
  56. bool IsEmpty() const { return (m_pNode == NULL); };
  57. // Methods
  58. public:
  59. // insert a node under another node
  60. IXMLDOMNode* InsertChild
  61. (
  62. IN IXMLDOMNode* pChildNode,
  63. IN const CComVariant& vAfter = CComVariant()
  64. ) throw(HRESULT);
  65. // append a node after a particular child node
  66. void AppendChild
  67. (
  68. IN CXMLNode& childNode,
  69. OUT IXMLDOMNode** ppNewChildNode = NULL
  70. ) throw(HRESULT);
  71. // set an attribute to a GUID value
  72. void SetAttribute
  73. (
  74. IN LPCWSTR wszAttributeName,
  75. IN GUID ValueId
  76. ) throw(HRESULT);
  77. // set value of a byte array attribute by UUENCODING the data
  78. void SetAttribute
  79. (
  80. LPCWSTR wszAttr,
  81. const BYTE *pbVal,
  82. UINT cbVal
  83. );
  84. // set the value of an attribute to an ASCII string
  85. void SetAttribute
  86. (
  87. IN LPCWSTR wszAttrName,
  88. IN LPCSTR szValue
  89. );
  90. // set an attribute to a string value
  91. void SetAttribute
  92. (
  93. IN LPCWSTR wszAttributeName,
  94. IN LPCWSTR wszValue
  95. ) throw(HRESULT);
  96. // set an attribute to an integer value
  97. void SetAttribute
  98. (
  99. IN LPCWSTR wszAttributeName,
  100. IN INT nValue
  101. ) throw(HRESULT);
  102. // set an attribute to a DWORD value
  103. void SetAttribute
  104. (
  105. IN LPCWSTR wszAttributeName,
  106. IN DWORD dwValue
  107. ) throw(HRESULT);
  108. // set an attribute to a LONGLONG value
  109. void SetAttribute
  110. (
  111. IN LPCWSTR wszAttributeName,
  112. IN LONGLONG llValue
  113. ) throw(HRESULT);
  114. // set the text value of a node
  115. void SetValue
  116. (
  117. IN LPCWSTR wszValue
  118. ) throw(HRESULT);
  119. // add text to a node
  120. void AddText
  121. (
  122. IN LPCWSTR wszText
  123. );
  124. IXMLDOMDocument *GetDocument()
  125. {
  126. return m_pDoc;
  127. }
  128. IXMLDOMNode *GetNodeInterface()
  129. {
  130. return m_pNode;
  131. }
  132. // save the node as an XML string
  133. BSTR SaveAsXML() throw(HRESULT);
  134. // insert a node as a child of the current node
  135. CXMLNode InsertNode
  136. (
  137. CXMLNode &node
  138. ) throw(HRESULT);
  139. // Data members
  140. protected:
  141. // toplevel document
  142. CComPtr<IXMLDOMDocument> m_pDoc;
  143. // node
  144. CComPtr<IXMLDOMNode> m_pNode;
  145. };
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CXMLDocument
  148. class CXMLDocument: public CXMLNode
  149. {
  150. private:
  151. // node currently positioned on
  152. CComPtr<IXMLDOMNode> m_pNodeCur;
  153. // attribute map for node currently positioned on
  154. CComPtr<IXMLDOMNamedNodeMap> m_pAttributeMap;
  155. // level from root (0)
  156. unsigned m_level;
  157. // Constructors& destructors
  158. public:
  159. // constructor where toplevel document node is passed in
  160. CXMLDocument(IXMLDOMDocument* pDoc = NULL):
  161. m_pNodeCur(pDoc),
  162. m_pAttributeMap(NULL),
  163. CXMLNode(pDoc, pDoc),
  164. m_level(0)
  165. {
  166. }
  167. // constructor where both toplevel node and toplevel document
  168. // are passed in
  169. CXMLDocument(IXMLDOMNode *pNode, IXMLDOMDocument *pDoc) :
  170. m_pNodeCur(pNode),
  171. m_level(0),
  172. m_pAttributeMap(NULL),
  173. CXMLNode(pNode, pDoc)
  174. {
  175. }
  176. // copy constructor
  177. CXMLDocument(const CXMLDocument& doc):
  178. CXMLNode(doc),
  179. m_pNodeCur(doc.m_pNodeCur),
  180. m_level(doc.m_level)
  181. {
  182. }
  183. // convert a node into a document
  184. CXMLDocument(const CXMLNode& node) :
  185. CXMLNode(node),
  186. m_level(0)
  187. {
  188. m_pNodeCur = m_pNode;
  189. }
  190. // Methods
  191. public:
  192. // return interface to toplevel document
  193. IXMLDOMDocument* GetInterface() const { return m_pDoc; };
  194. // set toplevel node to be the current node
  195. void SetToplevel()
  196. {
  197. m_level = 0;
  198. m_pNode = m_pNodeCur;
  199. }
  200. // set a particular node as the toplevel node in the document
  201. void SetToplevelNode(CXMLNode &node)
  202. {
  203. m_level = 0;
  204. m_pNode = node.GetNodeInterface();
  205. m_pNodeCur = m_pNode;
  206. }
  207. // initialize the document
  208. void Initialize() throw(HRESULT);
  209. // create a node within the document
  210. CXMLNode CreateNode
  211. (
  212. IN LPCWSTR wszName,
  213. IN DOMNodeType nType = NODE_ELEMENT
  214. ) throw(HRESULT);
  215. // reset current position to toplevel node
  216. void ResetToDocument
  217. (
  218. );
  219. // reset position to the parent node
  220. void ResetToParent
  221. (
  222. ) throw(HRESULT);
  223. // move to next node within the document
  224. bool Next
  225. (
  226. IN bool fDescend = TRUE,
  227. IN bool fAscendAllowed = TRUE
  228. ) throw(HRESULT);
  229. // find a particular attribute of the current node
  230. bool FindAttribute
  231. (
  232. IN LPCWSTR wszAttrName,
  233. OUT BSTR *pbstrAttrValue
  234. ) throw(HRESULT);
  235. // position to the next attribute in the current node
  236. IXMLDOMNode *NextAttribute
  237. (
  238. );
  239. // find a particular sibling or child element
  240. bool FindElement
  241. (
  242. IN LPCWSTR wsz,
  243. IN bool bGotoChild
  244. );
  245. bool FindElementOneOf
  246. (
  247. IN LPCWSTR wsz[],
  248. IN LONG lArraySize,
  249. IN bool bGotoChild
  250. );
  251. // load the document from an XML string
  252. bool LoadFromXML
  253. (
  254. IN BSTR bstrXML
  255. ) throw(HRESULT);
  256. // load the document from a file (currently only
  257. // used for testing purposes)
  258. bool LoadFromFile
  259. (
  260. IN LPCWSTR wszFile
  261. ) throw(HRESULT);
  262. // return the curernt node
  263. inline IXMLDOMNode *GetCurrentNode()
  264. {
  265. return m_pNodeCur;
  266. }
  267. inline SetCurrentNode(IXMLDOMNode *pNode)
  268. {
  269. m_pNodeCur = pNode;
  270. }
  271. // return the current level from the toplevel node
  272. inline unsigned GetLevel() { return m_level; }
  273. private:
  274. // is the node an element with a specific element type
  275. bool IsNodeMatch
  276. (
  277. LPCWSTR wszElementType
  278. );
  279. };
  280. #endif // __VSS_XML_HXX__