XmlDocument.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace AppSecInc
4 {
5  namespace Xml
6  {
8  class XmlDocument
9  {
10  private:
11  bool _loaded;
12  MSXML2::IXMLDOMDocumentPtr _document;
13  static bool wstring2bool(const std::wstring&);
14  public:
15  XmlDocument();
17  void Create(const CLSID clsid = MSXML2::CLSID_DOMDocument);
19  void Load(const std::wstring& filename, const CLSID clsid = MSXML2::CLSID_DOMDocument);
21  void LoadXml(const std::wstring& xml, const CLSID clsid = MSXML2::CLSID_DOMDocument);
23  MSXML2::IXMLDOMNodePtr FindNode(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
25  bool HasNodes(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
27  bool HasNode(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
29  MSXML2::IXMLDOMNodePtr SelectNode(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
31  MSXML2::IXMLDOMNodeListPtr SelectNodes(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
33  MSXML2::IXMLDOMNodeListPtr FindNodes(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
35  std::wstring GetNodeXml(MSXML2::IXMLDOMNode * node) const;
37  std::wstring GetNodeValue(MSXML2::IXMLDOMNode * node) const;
39  bool GetNodeBoolValue(MSXML2::IXMLDOMNode * node) const;
41  bool GetNodeBoolValue(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
43  bool GetNodeBoolValue(const std::wstring& xpath, MSXML2::IXMLDOMNode * parent, bool defaultvalue) const;
45  std::wstring GetNodeValue(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
47  std::wstring GetNodeValue(const std::wstring& xpath, MSXML2::IXMLDOMNode *, const std::wstring& defaultvalue) const;
49  std::wstring GetNodeXml(const std::wstring& xpath, MSXML2::IXMLDOMNode * = NULL) const;
51  std::wstring GetNodeXml(const std::wstring& xpath, MSXML2::IXMLDOMNode *, const std::wstring& defaultvalue) const;
53  std::wstring GetXml() const;
55  MSXML2::IXMLDOMAttributePtr FindAttribute(const std::wstring& name, MSXML2::IXMLDOMNode * node) const;
57  std::wstring GetAttributeValue(MSXML2::IXMLDOMAttribute * attribute) const;
59  bool GetAttributeBoolValue(MSXML2::IXMLDOMAttribute * attribute) const;
61  std::wstring GetAttributeValue(const std::wstring& xpath, const std::wstring& attributename, MSXML2::IXMLDOMNode * = NULL) const;
63  MSXML2::IXMLDOMNodePtr AppendChild(const std::wstring& name, MSXML2::IXMLDOMNode * parent = NULL, const _variant_t & type = VT_NULL, LPCWSTR pszNamespaceUri = NULL);
65  MSXML2::IXMLDOMAttributePtr SetAttribute(const std::wstring& name, const std::wstring& value, MSXML2::IXMLDOMNode * node);
67  MSXML2::IXMLDOMAttributePtr SelectAttribute(const std::wstring& name, MSXML2::IXMLDOMNode *) const;
69  bool HasAttribute(const std::wstring& name, MSXML2::IXMLDOMNode *) const;
71  bool GetAttributeBoolValue(const std::wstring& name, MSXML2::IXMLDOMNode *) const;
73  bool GetAttributeBoolValue(const std::wstring& name, MSXML2::IXMLDOMNode *, bool defaultvalue) const;
75  std::wstring GetAttributeValue(const std::wstring& name, MSXML2::IXMLDOMNode *) const;
77  std::wstring GetAttributeValue(const std::wstring& name, MSXML2::IXMLDOMNode *, const std::wstring& defaultvalue) const;
79  std::wstring XslTransform(const std::wstring xslt_filename);
81  MSXML2::IXMLDOMDocument * operator->() const throw() { return _document.operator->(); }
83  std::wstring GetParseError() const;
84  };
85  }
86 }
std::wstring GetParseError() const
error
Definition: XmlDocument.cpp:11
MSXML2::IXMLDOMAttributePtr SelectAttribute(const std::wstring &name, MSXML2::IXMLDOMNode *) const
select attribute node
Definition: XmlDocument.cpp:323
std::wstring GetXml() const
get outer xml
Definition: XmlDocument.cpp:240
bool GetAttributeBoolValue(MSXML2::IXMLDOMAttribute *attribute) const
return a boolean value of an attribute
Definition: XmlDocument.cpp:414
std::wstring GetNodeXml(MSXML2::IXMLDOMNode *node) const
return node's string value
Definition: XmlDocument.cpp:386
bool HasAttribute(const std::wstring &name, MSXML2::IXMLDOMNode *) const
has attribute
Definition: XmlDocument.cpp:334
MSXML2::IXMLDOMNodePtr FindNode(const std::wstring &xpath, MSXML2::IXMLDOMNode *=NULL) const
find node, returns NULL if the node doesn't exist
Definition: XmlDocument.cpp:156
std::wstring XslTransform(const std::wstring xslt_filename)
transform an xml with xslt
Definition: XmlDocument.cpp:263
MSXML2::IXMLDOMNodeListPtr SelectNodes(const std::wstring &xpath, MSXML2::IXMLDOMNode *=NULL) const
select nodes
Definition: XmlDocument.cpp:146
MSXML2::IXMLDOMAttributePtr FindAttribute(const std::wstring &name, MSXML2::IXMLDOMNode *node) const
find an attribute
Definition: XmlDocument.cpp:307
MSXML2::IXMLDOMNodePtr SelectNode(const std::wstring &xpath, MSXML2::IXMLDOMNode *=NULL) const
select node
Definition: XmlDocument.cpp:136
An MSXML document.
Definition: XmlDocument.h:8
MSXML2::IXMLDOMNodePtr AppendChild(const std::wstring &name, MSXML2::IXMLDOMNode *parent=NULL, const _variant_t &type=VT_NULL, LPCWSTR pszNamespaceUri=NULL)
append a new node
Definition: XmlDocument.cpp:276
bool HasNode(const std::wstring &xpath, MSXML2::IXMLDOMNode *=NULL) const
has node
Definition: XmlDocument.cpp:197
MSXML2::IXMLDOMNodeListPtr FindNodes(const std::wstring &xpath, MSXML2::IXMLDOMNode *=NULL) const
find nodes, returns NULL if not found
Definition: XmlDocument.cpp:171
bool HasNodes(const std::wstring &xpath, MSXML2::IXMLDOMNode *=NULL) const
has nodes
Definition: XmlDocument.cpp:202
void Load(const std::wstring &filename, const CLSID clsid=MSXML2::CLSID_DOMDocument)
load an xml document
Definition: XmlDocument.cpp:50
MSXML2::IXMLDOMAttributePtr SetAttribute(const std::wstring &name, const std::wstring &value, MSXML2::IXMLDOMNode *node)
append a new node
Definition: XmlDocument.cpp:292
bool GetNodeBoolValue(MSXML2::IXMLDOMNode *node) const
return node's boolean value
Definition: XmlDocument.cpp:409
std::wstring GetNodeValue(MSXML2::IXMLDOMNode *node) const
return node's string value
Definition: XmlDocument.cpp:398
std::wstring GetAttributeValue(MSXML2::IXMLDOMAttribute *attribute) const
return the value of an attribute
Definition: XmlDocument.cpp:374
XmlDocument()
Definition: XmlDocument.cpp:6
MSXML2::IXMLDOMDocument * operator->() const
IXMLDOMDocument.
Definition: XmlDocument.h:81
void Create(const CLSID clsid=MSXML2::CLSID_DOMDocument)
create an empty xml document
Definition: XmlDocument.cpp:33
void LoadXml(const std::wstring &xml, const CLSID clsid=MSXML2::CLSID_DOMDocument)
load an xml buffer
Definition: XmlDocument.cpp:85


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com