all groups > dotnet xml > july 2003 >
You're in the

dotnet xml

group:

Transfer data from XML to Stream?


Transfer data from XML to Stream? Rich Wallace
7/31/2003 1:51:08 PM
dotnet xml:
Hi all,

I have a COM component that receives XML documents from MSMQ. Before I
process the final documents and pass it to my application, I want to modify
the format a bit, as in create a name/value pair structure from an element
structure or rename certain fields. I'm using XmlTextReader to read over
the original doc and I'm using XmlTextWriter to create a new XML file that I
essentially need to load up again into an XMLDocument object.

I'd rather write the modified XML to a stream local to my running instance
of the COM component rather than create another physical file then pick it
back up.

Here's what I'm doing now...

Dim oXmlRdr As New
XmlTextReader("C:\project_changes_7252003112639568.xml")
Dim sXmlDocName As String = "C:\GatewayProduct.xml"
Dim oXmlWtr As New XmlTextWriter(sXmlDocName, Nothing)
Dim oXmlDoc As New XmlDocument()

Try
With oXmlWtr
.Formatting = Formatting.Indented
.Indentation = 4
.WriteStartDocument()
.WriteStartElement("GatewayProject")

While oXmlRdr.Read
Select Case oXmlRdr.Name
Case "q1:CostCenter"
oXmlWtr.WriteElementString("CostCenter",
oXmlRdr.ReadString)
Case "q1:BranchID"
oXmlWtr.WriteElementString("BranchID",
oXmlRdr.ReadString)
End Select
End While

oXmlRdr.Close()

.WriteEndElement()
.WriteEndDocument()
.Flush()
.Close()

oXmlDoc.Load(sXmlDocName)
MsgBox(oXmlDoc.OuterXml)

End With
Catch
MsgBox(Err.Description)
End Try

Is there a more efficient way to do this to avoid creating the
C:\GatewayProduct.xml file and just usig the xml in a stream?

TIA
-Rich

Re: Transfer data from XML to Stream? SQL Server Development Team
7/31/2003 3:50:44 PM
You can create an XML text writer that writes to a string via StringWriter
or to a MemoryStream via StreamWriter which should be less overhead. You
should also be able to write directly to an XmlNode using the XmlNodeWriter
class described at http://www.xmlandasp.net/downloads/XmlNodeWriter.zip

--
This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]

Re: Transfer data from XML to Stream? Rich Wallace
7/31/2003 5:40:43 PM
Thank you for the info on this. Is there any possible way to see a basic
example in VB.NET as well? I've never actually seen C# until today.

-Rich

[quoted text, click to view]

Transfer data from XML to Stream? Mick
8/1/2003 7:29:54 AM
You could use and XSLT to modify the format.


[quoted text, click to view]
Re: Transfer data from XML to Stream? Anders Borum
8/1/2003 11:37:25 AM
[quoted text, click to view]

Then start looking, because it's a great language :-)

--
venlig hilsen / with regards
anders borum
--

AddThis Social Bookmark Button