You'll need a pointer to a contiguous chunk of memory holding your document (and, for the second parameter, the number of bytes in that chunk). Check the documentation for your String class to find out how (and whether) you can accomplish this. Alternatively, rather than loading your document into a String, allocate a buffer of XMLBytes and load it into there. Depending on the source and size of your documents, you might also want to consider whether it's a good idea to store them in a buffer for parsing. If you're parsing large documents that come across a network connection, for example, it might make sense to implement your own InputSource that provides bytes to the parser as they become available. If size is a concern, you should also consider using a SAX parser. DOM trees are convenient but large. Don't make the common mistake of thinking of XML documents as a sequence of ASCII characters (or any other 8-bit characters). XML documents can be encoded in a variety of ways, so what you're really dealing with is bytes. If you treat your buffers as 8-bit strings, sooner or later you'll regret it. ________________________________
From: Mannion, Enda [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 24, 2007 2:16 PM To: [email protected] Subject: RE: Creating DOMDoc from string That's great exactly what I was looking for. Can you tell me how to pass the string as the first parameter to MemBufInputSource. String xml = "<company></company>\"; MemBufInputSource* memBufIS = new MemBufInputSource ( (const XMLByte*)xml <-- what do I do here , strlen(xml) , gMemBufId , false ); Thanks, Enda ________________________________ From: Jesse Pelton [mailto:[EMAIL PROTECTED] Sent: 24 January 2007 13:17 To: [email protected] Subject: RE: Creating DOMDoc from string You need to create a MemBufInputSource. (The MemParse sample shows how to do this.) You'll pass the MemBufInputSource to DOMBuilder::parse(), which returns the DOMDocument. ________________________________ From: Mannion, Enda [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 24, 2007 7:58 AM To: [email protected] Subject: RE: Creating DOMDoc from string Thanks again I think I may be able to use the DOMBuilder class. But I want it to accept a string. The string contains an XML file, not a file path but the whole XML file is in the string and I want the parser to return a DOMDocument of this XML file, is this possible? The DOMBuilder has parse functions but I do not see one that accepts a string. Thanks, Enda ________________________________ From: Jesse Pelton [mailto:[EMAIL PROTECTED] Sent: 23 January 2007 19:28 To: [email protected] Subject: RE: Creating DOMDoc from string I don't understand the question. What does it mean to copy a string to a DOMDocument? A string is just a sequence of characters, while a DOMDocument is a hierarchical tree of nodes. Some serialization process is required to transform one into the other. If you use a DOMBuilder, the parse() method returns a DOMDocument. If you use a parser derived from AbstractDOMParser (like XercesDOMParser), you can call getDocument() to retrieve the document after calling parse(). If neither of these helps, perhaps it would help to send some pseudo-code showing what you've got so far and where you're stuck. ________________________________ From: Mannion, Enda [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 23, 2007 2:13 PM To: [email protected] Subject: RE: Creating DOMDoc from string Thanks, but I don't want to parse I want to copy the XML string to a DOMDocument object. Is this possible or is there a way to create the DomDocument from the parser? Thanks, Enda ________________________________ From: Jesse Pelton [mailto:[EMAIL PROTECTED] Sent: 23 January 2007 18:02 To: [email protected] Subject: RE: Creating DOMDoc from string See the MemParse sample. While it uses a SAX parser, the technique is the same for DOM. ________________________________ From: Mannion, Enda [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 23, 2007 12:28 PM To: [email protected] Subject: Creating DOMDoc from string Hi, I have a string that contains an XML doc, how can I create an instance of the DOMDocument class using this string. Is there a constructor to do this? I can not use the DOMParser to read a file in this case. Thanks, Enda
