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.

113 lines
3.0 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. sxsxmltree.h
  5. Abstract:
  6. Create a XML DOM tree during push-mode parsing
  7. Author:
  8. Xiaoyu Wu (xiaoyuw) Aug 2000
  9. Revision History:
  10. --*/
  11. #if !defined(_FUSION_SXS_XMLTREE_H_INCLUDED_)
  12. #define _FUSION_SXS_XMLTREE_H_INCLUDED_
  13. #pragma once
  14. #include "xmlparser.h"
  15. #include "fusionheap.h"
  16. // allocatememory for this element, and all its attributes once
  17. struct _SXS_XMLATTRIBUTE{
  18. PWSTR m_wszName;
  19. ULONG m_ulPrefixLen;
  20. PWSTR m_wszValue;
  21. };
  22. typedef struct _SXS_XMLATTRIBUTE SXS_XMLATTRIBUTE;
  23. class SXS_XMLTreeNode{
  24. public:
  25. friend VOID PrintTreeFromRoot(SXS_XMLTreeNode * Root);
  26. friend class SXS_XMLDOMTree;
  27. SXS_XMLTreeNode() :
  28. m_AttributeList(NULL),
  29. m_cAttributes(0),
  30. m_pwszStr(NULL),
  31. m_ulPrefixLen(0),
  32. m_pSiblingNode(NULL),
  33. m_pParentNode(NULL),
  34. m_pFirstChild(NULL),
  35. m_pMemoryPool(NULL) { }
  36. VOID DeleteSelf() { FUSION_DELETE_SINGLETON(this); }
  37. ~SXS_XMLTreeNode() {
  38. CSxsPreserveLastError ple;
  39. if (m_pMemoryPool != NULL)
  40. {
  41. FUSION_DELETE_ARRAY(m_pMemoryPool);
  42. m_pMemoryPool = NULL;
  43. }
  44. ple.Restore();
  45. }
  46. HRESULT CreateTreeNode(USHORT cNumRecs, XML_NODE_INFO** apNodeInfo);
  47. VOID PrintSelf();
  48. private:
  49. HRESULT ComputeBlockSize(USHORT cNumRecs, XML_NODE_INFO** apNodeInfo, DWORD * dwBlockSizeInBytes);
  50. // for each node, allocate memory once : compute the total spaces need for prefix, localname, and value,
  51. ULONG m_ulPrefixLen;
  52. PWSTR m_pwszStr; // Can be a name for ELEMENT, a value for a PCDATA
  53. SXS_XMLATTRIBUTE *m_AttributeList;
  54. USHORT m_cAttributes;
  55. SXS_XMLTreeNode *m_pSiblingNode;
  56. SXS_XMLTreeNode *m_pParentNode;
  57. SXS_XMLTreeNode *m_pFirstChild;
  58. BYTE *m_pMemoryPool; // memory for attribs array, name-value pairs and name-value for the node
  59. };
  60. class SXS_XMLDOMTree{
  61. public:
  62. HRESULT AddNode(USHORT cNumRecs, XML_NODE_INFO** apNodeInfo); // CreateNode calls this func to add node into the Tree,
  63. VOID ReturnToParent(); // EndChildren calls this func if "fEmpty=FALSE"
  64. VOID SetChildCreation(); // BeginChildren calls this func
  65. /*
  66. VOID TurnOffFirstChildFlag();
  67. */
  68. SXS_XMLDOMTree():
  69. m_fBeginChildCreation(FALSE),
  70. m_Root(NULL),
  71. m_pCurrentNode(NULL)
  72. { }
  73. VOID DeleteTreeBranch(SXS_XMLTreeNode * pNode);
  74. ~SXS_XMLDOMTree(){
  75. CSxsPreserveLastError ple;
  76. this->DeleteTreeBranch(m_Root); // do not delete its siblings
  77. ple.Restore();
  78. }
  79. VOID PrintTreeFromRoot(SXS_XMLTreeNode * Root);
  80. SXS_XMLTreeNode * GetRoot() {
  81. return m_Root;
  82. }
  83. private :
  84. BOOL m_fBeginChildCreation; // everytime, when BeginChild is called, it is set, once it is checked, set it to be FALSE
  85. SXS_XMLTreeNode * m_Root;
  86. SXS_XMLTreeNode * m_pCurrentNode;
  87. };
  88. #endif