First, you need to provide some specifics as to what you're doing and what's not working as expected. A small, well-organized code sample is one way to provide that.
Second, SAX may be a better (more natural and more efficient) solution to your problem than DOM. If you're just traversing the DOM in order to build your own in-memory representation, you could avoid the CPU and memory overhead of building a DOM by creating your objects in response to SAX events. And finally, you might want to look at CodeSynthesis XSD, "an open-source, cross-platform W3C XML Schema to C++ data binding compiler" based on Xerces (http://www.codesynthesis.com/products/xsd/) and similar products. -----Original Message----- From: Amit [mailto:[email protected]] Sent: Thursday, January 22, 2009 6:28 AM To: [email protected] Cc: Amitsingh Pardesi Subject: Parsing XML using DOM in VC++ Hi, I am using Visual Studio 2008 to develop a Windows Console Application. I need to parse the XML Buffer and create Class objects from each Element node and again re-create the XML from these objects. I am using Xerces 2.8 on Windows platform. I am able to do the same for a simple XML file like the one below: <?xml version="1.0" encoding="utf-8" ?> <RootInfo> <Node> <NodeID>81023492-ACA3-98Af-BF38-7242AQ87088X</NodeID> <NodeIP>192.168.0.222</NodeIP> <NodeUserName>abcd</NodeUserName> <NodePassword>aabbccdd</NodePassword> <NodeType>Source</NodeType> </Node> <Node> <NodeID>4S123492-ACG0-98Af-BF38-K900F787IJ5M</NodeID> <NodeIP>192.170.7.21</NodeIP> <NodeUserName>Amit</NodeUserName> <NodePassword>amitpass</NodePassword> <NodeType>GUI</NodeType> </Node> </RootInfo> But when it comes to a more complex XML file like the one mentioned below, <?xml version="1.0" standalone="yes"?> <RootInfo> <Request> <Command> <CommandID>5f27-4e40-b6da-b1cb</CommandID> <ObjectName>File</ObjectName> <OperationName>Add</OperationName> <CommandType>Sync</CommandType> </Command> <Data> <DataElem1> <Text1>ABC</Text1> <Text2>ASDH</Text2> </DataElem1> <DataElem2> <File1>asdas.bat</File1> <file2>askjd.doc</file2> </DataElem2> <Status> <state>append</state> <state>add</state> </Status> </Data> <Error> <ErrorID/> <ErrorMessage/> </Error> </Request> <Response> <Command> <CommandID>5f27-4e40-b6da-b1cb</CommandID> </Command> <Data> <DataElem2> <File1>asdas.bat</File1> <file2>askjd.doc</file2> </DataElem2> <Status> <state>appended</state> <state>added</state> </Status> </Data> <Error> <ErrorID>62342-s838s-34jf3-eir8e</ErrorID> <ErrorMessage>Command Success</ErrorMessage> </Error> </Response> </RootInfo> I am not able to parse it correctly using DOM. Each node has a corresponding Class to store the details. The class of RootInfo will have two members, by the name Request & Response beloging to Class ReqRes. They both will in turn have 3 members by the name Command, Data & Error of respective class and so on. How do I do this? Any pointer to resolve this will be appreciated. Regards, Amit
