Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML namespace problem

Status
Not open for further replies.

KAlfred

IS-IT--Management
Jul 2, 2002
46
0
0
US
I'm new to vb.net and xml so bear with me please. I'm working on a very simple program that will read an xml file into a dataset and then the dataset is bound to a datgrid for viewing. If I use the XML file that was generated by .net, this works fine. If I use my original XML file this does not work. I found that the file that .net generated under my project has a line referencing the namespace. The original xml file doesn't. My question is, is there a way to use the file that doesn't include the namespace? I will be receiving xml files that won't include the namespace so I will need to be able to load them.
 
I found a way around this problem.

Dim str As String
Dim str2 as string
Dim xfile As New XmlDataDocument()

'Loads the xml file as a xmldatadocument
xfile.Load("Pathname")

'Returns the Namespace that is in the file
str = xfile.DocumentElement.NamespaceURI
xfile = Nothing

'Sets the Dataset NameSpace to the same as the document
NewDataSet.Namespace = str

'Fills the Dataset with the XML file
NewDataSet.ReadXml("C:\Documents and Settings\KAlfred\Desktop\nutruck\NuTruckLoadRequestorPkgFmt.xml")

If someone has a better (or more correct) way to do this, feel free to post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top