JM wrote:
Most of the examples I've seen with XMLReaders, serialization, etc,.
involve a text file on a file system. Does anybody have a start to
finish VB.NET example of reading an XML Document object (binary) and
parsing it? The object I'm receiving is w3c compliant. I have
somewhat of a Java example (below), but I would like to know how to do
it in VB.NET. Thank you in advance.
import org.w3c.dom.Document;
import weblogic.apache.xml.serialize.OutputFormat;
import weblogic.apache.xml.serialize.XMLSerializer;
import java.io.StringWriter;
protected String convertDocumentToString(Document argDocument) throws
Exception {
StringWriter sw = new StringWriter();
OutputFormat of = new OutputFormat(argDocument,"UTF-8",false);
XMLSerializer xs = new XMLSerializer(sw,of);
xs.serialize(argDocument);
return sw.toString();
}
Why is a Java org.w3c.dom.Document object "binary"?
The .NET equivalent of the W3C DOM Document is System.Xml.XmlDocument.
If you have an XmlDocument instance then you have various ways to
serialize it, there is the OuterXml property which gives you a string so
you could simply do (VB pseudo code)
Function ConvertDocumentToString (argDocument As
System.Xml.XmlDocument) As String
Return argDocument.OuterXml
End Function
although writing a function at all seems a bit questionable if the
OuterXml property is all you need.
There are other ways, you can use the Save method of the document to
save to a StringWriter e.g. (again VB pseudo code!)
Function ConvertDocumentToString (argDocument As
System.Xml.XmlDocument) As String
Dim string_Writer as System.IO.StringWriter = new
System.IO.StringWriter()
argDocument.Save(string_Writer)
Return string_Writer.ToString()
End Function
Then there is the WriteTo method to write to an XmlWriter which could
also be used to serialize the document.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/