[program-l] Re: Visual Basic .net: getting XMLWriter not to access the Internet

  • From: "Pranav Lal" <pranav.lal@xxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Sun, 15 May 2011 01:39:15 +0530

Hi Ian,

Ms is indeed a memory stream. I have a third party component that outputs a
xml string. I need to format that string and write it out to a file. That
works nicely as long as I am connected to the Internet.
Dim myEncoder As New System.Text.UTF8Encoding
Dim bytes As Byte() = myEncoder.GetBytes(svs)
'svs is the unformatted xml string
Dim ms As MemoryStream = New MemoryStream(bytes)
Dim xmlr As XmlTextReader
        Dim tempFile As String =
System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) &
"\" & "xw.xml"
                Dim XMLWR As XmlTextWriter = New XmlTextWriter(tempFile,
Nothing)
xmlr = New XmlTextReader(ms)


        xmlr.WhitespaceHandling = WhitespaceHandling.None
        XMLWR.Formatting = Formatting.Indented


        While xmlr.Read
            XMLWR.WriteNode(xmlr, False)
        End While
            xmlr.Close()
            XMLWR.Flush()
            XMLWR.Close()
        
Pranav

-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx]
On Behalf Of flybynight
Sent: Saturday, May 14, 2011 11:33 PM
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Re: Visual Basic .net: getting XMLWriter not to access
the Internet

Hi Pranav

Not exactly sure what you're trying to do here. When you assign xmlr in the
first line, you are creating a new XmlTextReader passing the variable ms as
a constructor. What is ms? A memory stream containing the XML data to be
read? I suspect the error you are receiving is related to reading the XML
data rather than writing nodes to the XmlWriter XMLWR.

There is no need to access the internet to write XML data. If you want the
writer to include a namespace, you can obviously specify one yourself but if
you don't, I can't see MS requiring that the computer running such code must
be connected to the internet.  

I'd suggest looking at where xmlr is reading from rather than the XMLWR.

Cheers
Ian

-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx]
On Behalf Of Pranav Lal
Sent: 14 May 2011 18:10
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Visual Basic .net: getting XMLWriter not to access the
Internet

Hi all,

I have the following code in my application
        xmlr = New XmlTextReader(ms)
        xmlr.WhitespaceHandling = WhitespaceHandling.None
        XMLWR.Formatting = Formatting.Indented


        While xmlr.Read
            XMLWR.WriteNode(xmlr, False)
        End While
        Try
            xmlr.Close()
            XMLWR.Flush()
            XMLWR.Close()
        Catch lx As Exception
            MsgBox("Error in writing temporary xml. Quitting")
            My.Application.Log.WriteException(lx)
            quit()
        End Try
        XMLWR = Nothing
        xmlr = Nothing

When the code reaches the line            XMLWR.WriteNode(xmlr, False) it
accesses the Internet to lookup the XML schemas I presume. I do not want the
code to access the Internet since my user should be able to run the
application offline. 

What do I do?
Pranav

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: