25 #include <Base/Common/XMLIO.hh>
26 #include <libxml/encoding.h>
42 string ConvertBSTRToString(BSTR pSrc)
44 DWORD cb,cwch = ::SysStringLen(pSrc);
47 cb = ::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch + 1, NULL, 0, 0, 0);
52 if(!::WideCharToMultiByte(CP_ACP, 0,pSrc, cwch + 1, szOut, cb, 0, 0))
72 int main (
int ,
char** )
75 string MyAnsiString,MyUTF8String;
79 MyBstr = ::SysAllocStringLen(NULL,14);
95 MyAnsiString = ConvertBSTRToString(MyBstr);
101 xmlNodePtr currentNode2;
107 rootNode = myXML.
create(
"XMLTest");
112 myXML.
addAttribute(currentNode2,
"AsUTF8", MyUTF8String );
113 myXML.
addAttribute(currentNode2,
"AsAnsi", MyAnsiString );
115 myXML.
addContent(currentNode2, MyUTF8String );
117 string MyFilename =
"Test-"+MyAnsiString+
".xml";
118 if (myXML.
write(MyFilename) <0) exit(1);
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
int write(const std::string &Filename, bool AutoAddCompressionSuffix=true) const
Write the whole tree that was constructed in memory to disk.
xmlNodePtr create(const std::string &RootNodeName)
Create the base of a new XML-Tree in memory, already with a one and only root node.
static int IsoLatin1ToUtf8(const std::string &isoLatin1, std::string &utf8)
Convert character string from UTF-8 format to ISO 8895-1.
void addContent(const xmlNodePtr Node, const std::string &Content)
Add content to a node.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.