XML Serialization or XMLReader for binary object in VB.NET???

J

JM

Hello,

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();
}
 
M

Martin Honnen

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.
 
J

JM

Martin said:
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
<snip>

Martin, thank you for the reply. I guess "binary" was the wrong word
to use. I meant that I was not provided a string containing XML. I've
since found out that what I am being provided is an XMLBean, not an XML
document. Something tells me I cannot add an XMLBean reference to a
VB.NET project, because there is no support yet. Maybe I'm going have
to write a middle piece in Java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top