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.

137 lines
4.1 KiB

  1. #pragma once
  2. //
  3. // Per BryanT, either do not use #import, or checkin what it produces.
  4. //
  5. //#pragma warning(disable:4192) // automatically excluding 'IErrorInfo' while importing type library 'msxml3.dll'
  6. //#import "msxml3.dll"
  7. #include "fusion_msxml3.tlh"
  8. namespace F
  9. {
  10. void ThrowHresult(HRESULT hr);
  11. class CXmlWriter
  12. //
  13. // This class combines the interface pointers to one object.
  14. //
  15. {
  16. public:
  17. ~CXmlWriter() { Release(); }
  18. CXmlWriter()
  19. {
  20. HRESULT hr;
  21. if (FAILED(hr = this->IMXWriter.CreateInstance(const_cast<PWSTR>(L"Msxml2.MXXMLWriter.3.0"))))
  22. ThrowHresult(hr);
  23. this->ISAXContentHandler = this->IMXWriter;
  24. }
  25. void Release()
  26. {
  27. if (this->IMXWriter != NULL)
  28. {
  29. this->IMXWriter.Release();
  30. }
  31. if (this->ISAXContentHandler != NULL)
  32. {
  33. this->ISAXContentHandler.Release();
  34. }
  35. }
  36. HRESULT startDocument() { return this->ISAXContentHandler->startDocument(); }
  37. HRESULT endDocument() { return this->ISAXContentHandler->endDocument(); }
  38. HRESULT startElement(
  39. const wchar_t * pwchQName,
  40. int cchQName = -1,
  41. MSXML2::ISAXAttributes * pAttributes = NULL
  42. )
  43. {
  44. return this->startElement(L"", 0, L"", 0, pwchQName, cchQName, pAttributes);
  45. }
  46. void setLength(const wchar_t * pwch, int & cch)
  47. {
  48. if (cch == -1)
  49. cch = static_cast<int>(wcslen(pwch));
  50. }
  51. void setLengths(
  52. const wchar_t * pwchNamespaceUri,
  53. int & cchNamespaceUri,
  54. const wchar_t * pwchLocalName,
  55. int & cchLocalName,
  56. const wchar_t * pwchQName,
  57. int & cchQName)
  58. {
  59. setLength(pwchNamespaceUri, cchNamespaceUri);
  60. setLength(pwchLocalName, cchLocalName);
  61. setLength(pwchQName, cchQName);
  62. }
  63. HRESULT startElement(
  64. const wchar_t * pwchNamespaceUri,
  65. int cchNamespaceUri,
  66. const wchar_t * pwchLocalName,
  67. int cchLocalName,
  68. const wchar_t * pwchQName,
  69. int cchQName,
  70. MSXML2::ISAXAttributes * pAttributes)
  71. {
  72. setLengths(pwchNamespaceUri, cchNamespaceUri, pwchLocalName, cchLocalName, pwchQName, cchQName);
  73. return this->ISAXContentHandler->startElement(
  74. pwchNamespaceUri, cchNamespaceUri, pwchLocalName,
  75. cchLocalName, pwchQName, cchQName, pAttributes);
  76. }
  77. HRESULT endElement(
  78. const wchar_t * pwchQName,
  79. int cchQName = -1)
  80. {
  81. return this->endElement(L"", 0, L"", 0, pwchQName, cchQName);
  82. }
  83. HRESULT endElement(
  84. const wchar_t * pwchNamespaceUri,
  85. int cchNamespaceUri,
  86. const wchar_t * pwchLocalName,
  87. int cchLocalName,
  88. const wchar_t * pwchQName,
  89. int cchQName)
  90. {
  91. setLengths(pwchNamespaceUri, cchNamespaceUri, pwchLocalName, cchLocalName, pwchQName, cchQName);
  92. return this->ISAXContentHandler->endElement(
  93. pwchNamespaceUri, cchNamespaceUri, pwchLocalName,
  94. cchLocalName, pwchQName, cchQName);
  95. }
  96. HRESULT characters(
  97. const wchar_t * pwchChars,
  98. int cchChars = -1)
  99. {
  100. setLength(pwchChars, cchChars);
  101. return this->ISAXContentHandler->characters(pwchChars, cchChars);
  102. }
  103. __declspec(property(get=Getindent,put=Putindent)) VARIANT_BOOL indent;
  104. void Putindent(VARIANT_BOOL fIndentMode) { this->IMXWriter->indent = fIndentMode; }
  105. VARIANT_BOOL Getindent() { return this->IMXWriter->indent; }
  106. __declspec(property(get=Getoutput,put=Putoutput)) _variant_t output;
  107. void Putoutput(const _variant_t & varDestination) { this->IMXWriter->output = varDestination; }
  108. _variant_t Getoutput() { return this->IMXWriter->output; }
  109. __declspec(property(get=Getencoding,put=Putencoding)) _bstr_t encoding;
  110. void Putencoding(_bstr_t strEncoding) { this->IMXWriter->encoding = strEncoding; }
  111. _bstr_t Getencoding() { return this->IMXWriter->encoding; }
  112. MSXML2::IMXWriterPtr IMXWriter;
  113. MSXML2::ISAXContentHandlerPtr ISAXContentHandler;
  114. };
  115. }