HighTechTalks DotNet Forums  

Reading XML with VB.NET

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Reading XML with VB.NET in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jessard
 
Posts: n/a

Default Reading XML with VB.NET - 10-13-2004 , 12:59 AM






Hi all,

I have an XML file that I wish to load and use with VB.NET. It is in the
structure:

<?xml version="1.0" encoding="UTF-16"?>
<sql xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet">
<insert>INSERT INTO ClientCarriers VALUES ('AC',5)</insert>
<insert>INSERT INTO ClientCarriers VALUES ('AC',6)</insert>
</sql>

I am trying to read through the nodes in the sql element with VB.NET. At
the moment I am using...

Dim doc As System.Xml.XmlDocument
Dim reader As System.Xml.XmlTextReader
Dim nodes As System.Xml.XmlNodeList
Dim node As System.Xml.XmlNode
Dim root As XmlElement

Try
doc = New XmlDocument
Dim str As String
str = MapPath(".") & "\basic2.xml"
reader = New XmlTextReader(str)
doc.PreserveWhitespace = True
doc.Load(reader)
Catch ex As Exception
'output message
End Try

An exception is thrown on the line doc.Load(reader):
"There is no Unicode byte order mark. Cannot switch to Unicode."

What do i have to do to get this working?

Any help would be appreciated,
Jesse

Reply With Quote
  #2  
Old   
Daniel O'Connell [C# MVP]
 
Posts: n/a

Default Re: Reading XML with VB.NET - 10-13-2004 , 01:13 AM







"Jessard" <Jessard (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi all,

I have an XML file that I wish to load and use with VB.NET. It is in the
structure:

?xml version="1.0" encoding="UTF-16"?
sql xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet"
insert>INSERT INTO ClientCarriers VALUES ('AC',5)</insert
insert>INSERT INTO ClientCarriers VALUES ('AC',6)</insert
/sql

snip
An exception is thrown on the line doc.Load(reader):
"There is no Unicode byte order mark. Cannot switch to Unicode."

Saving the XML file as UTF-16 with a byte order mark would be best.
How are you getting the XML file?




Reply With Quote
  #3  
Old   
Jessard
 
Posts: n/a

Default Re: Reading XML with VB.NET - 10-13-2004 , 02:07 AM



it is the result of a transform using my own stylesheet and VB.NET.

ie.
Dim sOutXML = MapPath(".") & "\template.xml"
Dim whiteboardPath = MapPath(".") & "\whiteboard.xml"
Dim xslTran As Xsl.XslTransform = New Xsl.XslTransform

xslTran.Load(MapPath(".") & "\ClientsTemplate.xsl")
xslTran.Transform(sOutXML, whiteboardPath)

i don't necessarily want it to be UTF-16 but that is what results. I just
want to be able to read it back again.

"Daniel O'Connell [C# MVP]" wrote:

Quote:
"Jessard" <Jessard (AT) discussions (DOT) microsoft.com> wrote in message
news:2312877E-A928-4D92-AB55-D6F6B346150B (AT) microsoft (DOT) com...
Hi all,

I have an XML file that I wish to load and use with VB.NET. It is in the
structure:

?xml version="1.0" encoding="UTF-16"?
sql xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet"
insert>INSERT INTO ClientCarriers VALUES ('AC',5)</insert
insert>INSERT INTO ClientCarriers VALUES ('AC',6)</insert
/sql

snip
An exception is thrown on the line doc.Load(reader):
"There is no Unicode byte order mark. Cannot switch to Unicode."


Saving the XML file as UTF-16 with a byte order mark would be best.
How are you getting the XML file?




Reply With Quote
  #4  
Old   
Daniel O'Connell [C# MVP]
 
Posts: n/a

Default Re: Reading XML with VB.NET - 10-15-2004 , 11:26 PM



Hmm, sorry about the delay in responding.

DO you think you could write a short but complete[1] console application
taht exhibits the problem? It may be easier to diagnos that way.

1. http://yoda.arachsys.com/csharp/complete.html (examples are in C#, but it
still applies)
"Jessard" <Jessard (AT) discussions (DOT) microsoft.com> wrote

Quote:
it is the result of a transform using my own stylesheet and VB.NET.

ie.
Dim sOutXML = MapPath(".") & "\template.xml"
Dim whiteboardPath = MapPath(".") & "\whiteboard.xml"
Dim xslTran As Xsl.XslTransform = New Xsl.XslTransform

xslTran.Load(MapPath(".") & "\ClientsTemplate.xsl")
xslTran.Transform(sOutXML, whiteboardPath)

i don't necessarily want it to be UTF-16 but that is what results. I just
want to be able to read it back again.

"Daniel O'Connell [C# MVP]" wrote:


"Jessard" <Jessard (AT) discussions (DOT) microsoft.com> wrote in message
news:2312877E-A928-4D92-AB55-D6F6B346150B (AT) microsoft (DOT) com...
Hi all,

I have an XML file that I wish to load and use with VB.NET. It is in
the
structure:

?xml version="1.0" encoding="UTF-16"?
sql xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet"
insert>INSERT INTO ClientCarriers VALUES ('AC',5)</insert
insert>INSERT INTO ClientCarriers VALUES ('AC',6)</insert
/sql

snip
An exception is thrown on the line doc.Load(reader):
"There is no Unicode byte order mark. Cannot switch to Unicode."


Saving the XML file as UTF-16 with a byte order mark would be best.
How are you getting the XML file?






Reply With Quote
  #5  
Old   
Jessard
 
Posts: n/a

Default Re: Reading XML with VB.NET - 10-17-2004 , 07:31 PM



Hi Daniel, thanks for getting back to me. Here are details of the console
app you suggested.

This is my console app:

Imports System.Xml

Module Module1

Sub Main()
Dim doc As XmlDocument
Dim reader As XmlTextReader
Dim str As String

Try
doc = New XmlDocument
str = "..\basic2.xml"
reader = New XmlTextReader(str)
doc.PreserveWhitespace = True
doc.Load(reader)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

Console.ReadLine()

End Sub

End Module


This is my output:

There is no Unicode byte order mark. Cannot switch to Unicode.


This is my basic2.xml file.

<?xml version="1.0" encoding="UTF-16"?>
<sql xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet">
<insert>INSERT INTO ClientCarriers VALUES ('AX',6)</insert>
<insert>INSERT INTO ClientCarriers VALUES ('AX',2)</insert>
</sql>



"Daniel O'Connell [C# MVP]" wrote:

Quote:
Hmm, sorry about the delay in responding.

DO you think you could write a short but complete[1] console application
taht exhibits the problem? It may be easier to diagnos that way.

1. http://yoda.arachsys.com/csharp/complete.html (examples are in C#, but it
still applies)
"Jessard" <Jessard (AT) discussions (DOT) microsoft.com> wrote in message
news:5EEBD6F8-272D-4E2B-B69A-9B68F703F962 (AT) microsoft (DOT) com...
it is the result of a transform using my own stylesheet and VB.NET.

ie.
Dim sOutXML = MapPath(".") & "\template.xml"
Dim whiteboardPath = MapPath(".") & "\whiteboard.xml"
Dim xslTran As Xsl.XslTransform = New Xsl.XslTransform

xslTran.Load(MapPath(".") & "\ClientsTemplate.xsl")
xslTran.Transform(sOutXML, whiteboardPath)

i don't necessarily want it to be UTF-16 but that is what results. I just
want to be able to read it back again.

"Daniel O'Connell [C# MVP]" wrote:


"Jessard" <Jessard (AT) discussions (DOT) microsoft.com> wrote in message
news:2312877E-A928-4D92-AB55-D6F6B346150B (AT) microsoft (DOT) com...
Hi all,

I have an XML file that I wish to load and use with VB.NET. It is in
the
structure:

?xml version="1.0" encoding="UTF-16"?
sql xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet"
insert>INSERT INTO ClientCarriers VALUES ('AC',5)</insert
insert>INSERT INTO ClientCarriers VALUES ('AC',6)</insert
/sql

snip
An exception is thrown on the line doc.Load(reader):
"There is no Unicode byte order mark. Cannot switch to Unicode."


Saving the XML file as UTF-16 with a byte order mark would be best.
How are you getting the XML file?







Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.