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.

114 lines
2.9 KiB

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