Tdar

Hello,

I probally am doing something wrong, please note that this xml data can be read with xml notepad 2007 fine.

I have the following code:

Dim UPS_BILL As New System.Xml.XmlDocument

UPS_BILL.Load("C:/UPSXML.XML")

TextBox1.Text = "UPS XML DATA:" & vbCrLf
If IsDBNull(UPS_BILL.SelectSingleNode("UPS_EBR_BILL/XMLBillFileVersion")) Then <--- Errors here
Else
TextBox1.Text = TextBox1.Text & UPS_BILL.SelectSingleNode("UPS_EBR_BILL/XMLBillFileVersion").InnerText.ToString
End If


i get the following error:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="UPS_XML_WEEKLY_PARCER"
StackTrace:
at UPS_XML_WEEKLY_PARCER.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\djp\My Documents\Visual Studio 2005\Projects\UPS_XML_WEEKLY_PARCER\UPS_XML_WEEKLY_PARCER\Form1.vb:line 15
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at UPS_XML_WEEKLY_PARCER.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

The here is a clip of the first few lines of the C:/UPSXML.XML xml file:

< xml version="1.0" encoding="ISO-8859-1" >
<UPS_EBR_BILL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ups.com/XMLSchema/EBR/Billing/v1" xsi:schemaLocation="http://www.ups.com/XMLSchema/EBR/Billing/v1 Billing_XML_Schema.xsd">
<XMLBillFileVersion>1.0.1</XMLBillFileVersion>

Tdar




Re: XML and the .NET Framework problem reading xml data

Martin Honnen

After the Load call do e.g.

Dim NSManager As XmlNamespaceManager = New XmlNamespaceManager(UPS_BILL.NameTable)

NSManager.AddNamespace("ups", "http://www.ups.com/XMLSchema/EBR/Billing/v1")

Dim Version As XmlNode = UPS_BILL.SelectSingleNode("ups:UPS_EBR_BILL/ups:XMLBillFileVersion", NSManager)

If Not Version Is Nothing Then

TextBox1.Text = TextBox1.Text & Version.InnerText

End If






Re: XML and the .NET Framework problem reading xml data

Tdar

Hello

thanks for that info, I am cerious and since I still dont know to much about working with xml thru asp.net 2

Do i have to do this for each node and sub node

Dim Version As XmlNode = UPS_BILL.SelectSingleNode("ups:UPS_EBR_BILL/ups:XMLBillFileVersion", NSManager)

If Not Version Is Nothing Then

IS there an easier way to reference the data, There is alot of data I need to access in this ups file

Tdar





Re: XML and the .NET Framework problem reading xml data

Martin Honnen

What is easy or easier depends on your skills. SelectSingleNode uses an XPath "http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx">XmlDataSource you can bind to controls. Then with ASP.NET there is the Xml web control allowing you to apply XSLT to output data. Some XML can be read in a DataSet and then be treated like relational data.