Source code of Windows XP (NT5)
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.

132 lines
3.5 KiB

  1. /********************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. pfxml.h
  5. Abstract:
  6. A simple XML parser & object model (for read only access to an XML
  7. file. This is heavily (nearly stolen) based on WSmith's SimpleXML
  8. stuff that he wrote for the Neptune comments button
  9. Revision History:
  10. DerekM created 03/15/00
  11. ********************************************************************/
  12. #ifndef PFXML_H
  13. #define PFXML_H
  14. #include "util.h"
  15. #include "pfarray.h"
  16. #include "pfhash.h"
  17. class CPFXMLParser;
  18. class CPFXMLNode;
  19. /////////////////////////////////////////////////////////////////////////////
  20. // enumerations
  21. enum EPFXMLNodeType
  22. {
  23. xmlntUnknown = 0,
  24. xmlntElement,
  25. xmlntText,
  26. };
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CPFXMLDocument
  29. class CPFXMLDocument : public CPFPrivHeapGenericClassBase
  30. {
  31. private:
  32. // member data
  33. CPFXMLNode *m_ppfxmlRoot;
  34. public:
  35. CPFXMLDocument(void);
  36. ~CPFXMLDocument(void);
  37. HRESULT get_RootNode(CPFXMLNode **pppfxmlRoot);
  38. HRESULT put_RootNode(CPFXMLNode *ppfxmlRoot);
  39. HRESULT ParseFile(LPWSTR wszFile);
  40. HRESULT ParseBlob(BYTE *pbBlob, DWORD cbBlob);
  41. HRESULT ParseStream(IStream *pStm, DWORD cbStm);
  42. HRESULT WriteFile(LPWSTR wszFile);
  43. };
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CPFArrayAttr definition
  46. class CPFArrayAttr : public CPFArrayBase
  47. {
  48. private:
  49. void DeleteItem(LPVOID pv);
  50. LPVOID AllocItemCopy(LPVOID pv);
  51. public:
  52. HRESULT CopyFrom(CPFArrayAttr *prg)
  53. {
  54. return internalCopyFrom(prg);
  55. }
  56. };
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CPFXMLDocument
  59. class CPFXMLNode : private CPFPrivHeapGenericClassBase, public IUnknown
  60. {
  61. friend class CPFXMLDocument;
  62. private:
  63. // memberdata
  64. CPFArrayUnknown m_rgChildren;
  65. EPFXMLNodeType m_xmlnt;
  66. CPFArrayAttr m_rgAttr;
  67. CComBSTR m_bstrTagData;
  68. DWORD m_cRef;
  69. // member functions
  70. CPFXMLNode(DWORD cRef);
  71. ~CPFXMLNode(void);
  72. HRESULT Write(HANDLE hFile);
  73. void Cleanup(void);
  74. public:
  75. static CPFXMLNode *CreateInstance(void);
  76. STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppv) { return E_NOTIMPL; }
  77. STDMETHOD_(ULONG, AddRef)(void);
  78. STDMETHOD_(ULONG, Release)(void);
  79. EPFXMLNodeType get_NodeType(void) { return m_xmlnt; }
  80. void put_NodeType(EPFXMLNodeType xmlnt) { m_xmlnt = xmlnt; }
  81. HRESULT get_Data(BSTR *pbstrData);
  82. HRESULT put_Data(LPCWSTR wszData, DWORD cch = (DWORD)-1);
  83. HRESULT append_Data(LPCWSTR wszData, DWORD cch = (DWORD)-1);
  84. DWORD get_AttributeCount(void) { return m_rgAttr.get_Highest() + 1; }
  85. HRESULT add_Attribute(LPCWSTR wszName, LPCWSTR wszVal,
  86. DWORD cchName = (DWORD)-1, DWORD cchVal = (DWORD)-1);
  87. HRESULT get_Attribute(LPCWSTR wszName, BSTR *pbstrVal);
  88. HRESULT get_Attribute(DWORD iAttr, BSTR *pbstrVal);
  89. DWORD get_ChildCount(void) { return m_rgChildren.get_Highest() + 1; }
  90. HRESULT DeleteAllChildren(void);
  91. HRESULT append_Child(CPFXMLNode *ppfxml);
  92. HRESULT append_Children(CPFArrayUnknown &rgNodes);
  93. HRESULT get_Child(DWORD iChild, CPFXMLNode **pppfxml);
  94. HRESULT get_MatchingChildElements(LPCWSTR wszTag, CPFArrayUnknown &rgNodes);
  95. HRESULT get_ChildText(BSTR *pbstrText);
  96. HRESULT CloneNode(CPFXMLNode **pppfxml, BOOL fWantChildren = TRUE);
  97. };
  98. #endif