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

  • From: Pranav Lal <pranav.lal@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Tue, 17 May 2011 17:11:05 +0530

Ian,
Ignore the bit about specifying the encoding when using a xmlDocument.
I have found a way to do this using a XMLTextWriter. I will try it and
revert.

On 5/17/11, Pranav Lal <pranav.lal@xxxxxxxxx> wrote:
> Hi Ian,
>
> As for what I am trying to do, I have a third party component that
> outputs unformatted XML. I am using the XMLReader and XMLTextWriter
> classes to write out formatted XML. After that, I edit the XML using
> string manupulation. I find it easier to do then using the actual XML
> cklasses. I would be happy to use the xml document class. However, I
> cannot see how to output data from it as UTF-8. All strings in visual
> basic .net are set to UTF-16.
>
> Pranav
>
> On 5/17/11, Ian Sharpe <isforums@xxxxxxxx> wrote:
>> It's been a while since I've used these classes but am sure the
>> XmlReaderSettings class will have a validate property or something like
>> that. In general, I tended to use the XmlDocument class which I found
>> easier
>> to work with with and didn't really have to worry about performance.
>> Obviously it depends on exactly what you are trying to do. What exactly
>> are
>> you trying to do by the way?
>>
>> In summary, you could try create a new XmlDocument object. Then use the
>> Load
>> method to load an XML file from the filesystem or internet, passing it
>> the
>> path/uri to the file. Or you can simply load raw XML into the object
>> using
>> the LoadXml method, passing it an XML string.
>>
>> I can't remember off the top of my head but suspect that by default, the
>> Xml
>> won't be validated. If I'm wrong, I think there's a Validate property
>> that
>> you can set to false before loading the Xml.
>>
>> You will theen be able to work with the entire XmlDocument in memory. If
>> you
>> file is large, this may be an issue.
>>
>> If you only want to extract parts of the Xml file, it may well be much
>> simpler to use an XSL transform. If you're not familiar with XSL, this
>> will
>> be a steap learning curve but a good one in my view and worth tackling.
>>
>> Cheers
>> Ian
>>
>> -----Original Message-----
>> From: program-l-bounce@xxxxxxxxxxxxx
>> [mailto:program-l-bounce@xxxxxxxxxxxxx]
>> On Behalf Of Pranav Lal
>> Sent: 17 May 2011 11:50
>> To: program-l@xxxxxxxxxxxxx
>> Subject: [program-l] Re: Visual Basic .net: getting XMLWriter not to
>> access
>> the Internet
>>
>> Hi Ian,
>> <snip
>> 1. It maybe that the XmlTextReader is validating the XML file and in
>> order
>> to do this, it is looking for the scheme or DTD referrenced in the XML
>> file.
>> You could try turning validation off for the XmlTextReader.
>> PL] How do I do this? I know that I need to use a XMLReaderSettings
>> object
>> but how do I apply that to the XMLTextWriter? I ask since the
>> XMLTextWriter
>> does not have a suitable constructer. There is the create method which
>> takes
>> a stream and a settings object but I can't figure out how to put all of
>> this
>> together.
>>
>> Pranav
>>
>> On 5/17/11, Ian Sharpe <isforums@xxxxxxxx> wrote:
>>> Hi Pranav
>>>
>>>
>>> I am assuming that you are not interested in the resource that the
>>> XmlTextReader is going to the web to retrieve? Ie. That you are only
>>> interested in the raw XML data? Here are a couple of other suggestions
>>> that may help:
>>>
>>> 1. It maybe that the XmlTextReader is validating the XML file and in
>>> order to do this, it is looking for the scheme or DTD referrenced in the
>> XML file.
>>> You could try turning validation off for the XmlTextReader.
>>>
>>> 2. You could also simply remove the reference to the external file
>>> from the XML file before you try reading it.
>>>
>>> Obviously you run the risk of handling potentially invalid XML files
>>> but I suspect this won't be important in your scenario. If it is, then
>>> you could always retrieve the external resources with the XML file
>>> itself, save them all locally, and modify the references in the XML to
>>> point to the local copies. Again, if the schema changes, your app may
>>> fail, but then this would be the case if you were reading the
>>> validating anyway and would require changes to your code to allow for
>>> any
>> relevant changes anyway.
>>>
>>> Cheers
>>> Ian
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: program-l-bounce@xxxxxxxxxxxxx
>>> [mailto:program-l-bounce@xxxxxxxxxxxxx]
>>> On Behalf Of Pranav Lal
>>> Sent: 17 May 2011 01:51
>>> To: program-l@xxxxxxxxxxxxx
>>> Subject: [program-l] Re: Visual Basic .net: getting XMLWriter not to
>>> access the Internet
>>>
>>> Hi Ian,
>>>
>>> Yes and the code does not go out to the web. I have read some more and
>>> suspect that I need to set the xml resolver to nothing. I know that I
>>> have to use the xml reader settings object but cannot see how to do
>>> that.
>>>
>>> In addition, I tried switching to using the xmlDocument object since
>>> it is easy to set the resolver to nothing but that lead to a host of
>>> problems so I wont go there yet.
>>>
>>> Pranav
>>> -----Original Message-----
>>> From: program-l-bounce@xxxxxxxxxxxxx
>>> [mailto:program-l-bounce@xxxxxxxxxxxxx]
>>> On Behalf Of Ian Sharpe
>>> Sent: Monday, May 16, 2011 8:49 PM
>>> To: program-l@xxxxxxxxxxxxx
>>> Subject: [program-l] Re: Visual Basic .net: getting XMLWriter not to
>>> access the Internet
>>>
>>> Did you try the passing in the simplified XML I provided or something
>>> similar?
>>>
>>> Cheers
>>> ian
>>>
>>> -----Original Message-----
>>> From: program-l-bounce@xxxxxxxxxxxxx
>>> [mailto:program-l-bounce@xxxxxxxxxxxxx]
>>> On Behalf Of Pranav Lal
>>> Sent: 16 May 2011 15:49
>>> To: program-l@xxxxxxxxxxxxx
>>> Subject: [program-l] Re: Visual Basic .net: getting XMLWriter not to
>>> access the Internet
>>>
>>> Sorry,
>>>
>>> I have now tried setting standalone to "yes" without any success.
>>>
>>> Pranav
>>>
>>> -----Original Message-----
>>> From: program-l-bounce@xxxxxxxxxxxxx
>>> [mailto:program-l-bounce@xxxxxxxxxxxxx]
>>> On Behalf Of Soronel Haetir
>>> Sent: Monday, May 16, 2011 6:40 AM
>>> To: program-l@xxxxxxxxxxxxx
>>> Subject: [program-l] Re: Visual Basic .net: getting XMLWriter not to
>>> access the Internet
>>>
>>> Pranav,
>>>
>>> David was suggesting that you try setting standalone to "yes".
>>>
>>> On 5/15/11, Pranav Lal <pranav.lal@xxxxxxxxx> wrote:
>>>> Hi David and Ian,
>>>>
>>>> I have tried setting standalone="no" without any success. The problem
>>> seems
>>>> to be that the program is going out to look for the document type
>>>> definition. I ran a network sniffer and can see this clearly. In case
>>> anyone
>>>> is curious, I have uploaded the first packet my program sends to my
>>>> dropbox's public folder. You can get the text file containing the
>>>> packet from http://dl.dropbox.com/u/3688386/ProgramPackets.txt
>>>>
>>>> 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
>>>>
>>>
>>>
>>> --
>>> Soronel Haetir
>>> soronel.haetir@xxxxxxxxx
>>> ** 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
>>>
>>> ** 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
>>
>> ** 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: