By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Append Child Nodes XML in Memory

P: n/a
I know I have been asking LOTS of xml questions and I really apprecaite all
the help.

Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>

<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwell</company>
<address>Street Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>

<!-- Next product here-->
</products>
I am loading the doc in memory using xmlDocument
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)
End Sub

Here is when my problem starts. I have a form with all the information that
I needed "appended" to the XMLdoc (in memory). I tried

Private Sub AddProduct(ByVal node As XmlNode)
Dim xmlProductName = txtProduct.Text
Dim xmlCompanyName = txtCompany.Text
Dim xmlAddress = txtAddress.Text
Dim xmlCity = txtCity.Text
Dim xmlState = cmboState.Text
Dim xmlZip = txtZip.Text
node.AppendChild(xmlProductName)
node.AppendChild(xmlCompanyName)
node.AppendChild(xmlAddress)
node.AppendChild(xmlCity)
node.AppendChild(xmlState)
node.AppendChild(xmlZip)
End Sub

But I am really confused on what node to pass. Any help would be apprciated.
Jul 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
AddProduct(xmlDoc.SelectSingleNode("/"))

/ is the XPath for the root node.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
I know I have been asking LOTS of xml questions and I really apprecaite all
the help.

Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>

<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwell</company>
<address>Street Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>

<!-- Next product here-->
</products>
I am loading the doc in memory using xmlDocument
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)
End Sub

Here is when my problem starts. I have a form with all the information
that
I needed "appended" to the XMLdoc (in memory). I tried

Private Sub AddProduct(ByVal node As XmlNode)
Dim xmlProductName = txtProduct.Text
Dim xmlCompanyName = txtCompany.Text
Dim xmlAddress = txtAddress.Text
Dim xmlCity = txtCity.Text
Dim xmlState = cmboState.Text
Dim xmlZip = txtZip.Text
node.AppendChild(xmlProductName)
node.AppendChild(xmlCompanyName)
node.AppendChild(xmlAddress)
node.AppendChild(xmlCity)
node.AppendChild(xmlState)
node.AppendChild(xmlZip)
End Sub

But I am really confused on what node to pass. Any help would be
apprciated.

Jul 21 '05 #2

P: n/a
Whoops! That was silly, rather do:
AddProduct(xmlDoc.ChildNodes(0))
It'll be faster than using XPath.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
I know I have been asking LOTS of xml questions and I really apprecaite all
the help.

Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>

<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwell</company>
<address>Street Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>

<!-- Next product here-->
</products>
I am loading the doc in memory using xmlDocument
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)
End Sub

Here is when my problem starts. I have a form with all the information
that
I needed "appended" to the XMLdoc (in memory). I tried

Private Sub AddProduct(ByVal node As XmlNode)
Dim xmlProductName = txtProduct.Text
Dim xmlCompanyName = txtCompany.Text
Dim xmlAddress = txtAddress.Text
Dim xmlCity = txtCity.Text
Dim xmlState = cmboState.Text
Dim xmlZip = txtZip.Text
node.AppendChild(xmlProductName)
node.AppendChild(xmlCompanyName)
node.AppendChild(xmlAddress)
node.AppendChild(xmlCity)
node.AppendChild(xmlState)
node.AppendChild(xmlZip)
End Sub

But I am really confused on what node to pass. Any help would be
apprciated.

Jul 21 '05 #3

P: n/a
Now I am getting this error

Additional information: Specified cast is not valid.

error begins on this line
node.AppendChild(xmlProductName)

Thanks for the help.

Michae
"Sean Hederman" wrote:
Whoops! That was silly, rather do:
AddProduct(xmlDoc.ChildNodes(0))
It'll be faster than using XPath.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
I know I have been asking LOTS of xml questions and I really apprecaite all
the help.

Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>

<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwell</company>
<address>Street Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>

<!-- Next product here-->
</products>
I am loading the doc in memory using xmlDocument
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)
End Sub

Here is when my problem starts. I have a form with all the information
that
I needed "appended" to the XMLdoc (in memory). I tried

Private Sub AddProduct(ByVal node As XmlNode)
Dim xmlProductName = txtProduct.Text
Dim xmlCompanyName = txtCompany.Text
Dim xmlAddress = txtAddress.Text
Dim xmlCity = txtCity.Text
Dim xmlState = cmboState.Text
Dim xmlZip = txtZip.Text
node.AppendChild(xmlProductName)
node.AppendChild(xmlCompanyName)
node.AppendChild(xmlAddress)
node.AppendChild(xmlCity)
node.AppendChild(xmlState)
node.AppendChild(xmlZip)
End Sub

But I am really confused on what node to pass. Any help would be
apprciated.


Jul 21 '05 #4

P: n/a
What is the type of xmlProductName (check the runtime type in the debugger)?

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Now I am getting this error

Additional information: Specified cast is not valid.

error begins on this line
node.AppendChild(xmlProductName)

Thanks for the help.

Michae
"Sean Hederman" wrote:
Whoops! That was silly, rather do:
AddProduct(xmlDoc.ChildNodes(0))
It'll be faster than using XPath.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
>I know I have been asking LOTS of xml questions and I really apprecaite
>all
> the help.
>
> Here is my XML file
> <?xml version="1.0" encoding="utf-8" ?>
>
> <products>
> <!-- Repeat the structure below for each product. -->
> <product>
> <id>CP-90, T-32</id>
> <company>Carwell</company>
> <address>Street Address</address>
> <city>City</city>
> <state>State</state>
> <zip>Zip</zip>
> </product>
>
> <!-- Next product here-->
> </products>
>
>
> I am loading the doc in memory using xmlDocument
> Dim xmlFile As String = xmlLocation()
> Dim xmlDoc As XmlDocument
>
> Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> xmlDoc = New XmlDocument
> xmlDoc.Load(xmlFile)
>
>
> End Sub
>
> Here is when my problem starts. I have a form with all the information
> that
> I needed "appended" to the XMLdoc (in memory). I tried
>
> Private Sub AddProduct(ByVal node As XmlNode)
> Dim xmlProductName = txtProduct.Text
> Dim xmlCompanyName = txtCompany.Text
> Dim xmlAddress = txtAddress.Text
> Dim xmlCity = txtCity.Text
> Dim xmlState = cmboState.Text
> Dim xmlZip = txtZip.Text
> node.AppendChild(xmlProductName)
> node.AppendChild(xmlCompanyName)
> node.AppendChild(xmlAddress)
> node.AppendChild(xmlCity)
> node.AppendChild(xmlState)
> node.AppendChild(xmlZip)
> End Sub
>
> But I am really confused on what node to pass. Any help would be
> apprciated.


Jul 21 '05 #5

P: n/a
Here is my debug output.

'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorl ib.dll', No symbols loaded.
'Zadig': Loaded 'C:\Documents and Settings\mlubrano\My Documents\Visual
Studio Projects\Zadig\bin\Zadig.exe', Symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.windows.forms\1.0.50 00.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c56 1934e089\system.dll', No
symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5 000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll' , No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__ b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a 5c561934e089\system.xml.dll', No symbols loaded.
An unhandled exception of type 'System.InvalidCastException' occurred in
Zadig.exe

Additional information: Specified cast is not valid.
Unhandled Exception: System.InvalidCastException: Specified cast is not valid.
at Zadig.Products.AddProduct(XmlNode node) in C:\Documents and
Settings\mlubrano\My Documents\Visual Studio Projects\Zadig\Products.vb:line
239
at Zadig.Products.bttnAdd_Click(Object sender, EventArgs e) in
C:\Documents and Settings\mlubrano\My Documents\Visual Studio
Projects\Zadig\Products.vb:line 223
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs 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.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Zadig.Zadig.Main() in C:\Documents and Settings\mlubrano\My
Documents\Visual Studio Projects\Zadig\Main.vb:line 3The program '[328]
Zadig.exe' has exited with code 0 (0x0).

"fremenusul" wrote:
Now I am getting this error

Additional information: Specified cast is not valid.

error begins on this line
node.AppendChild(xmlProductName)

Thanks for the help.

Michae
"Sean Hederman" wrote:
Whoops! That was silly, rather do:
AddProduct(xmlDoc.ChildNodes(0))
It'll be faster than using XPath.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
I know I have been asking LOTS of xml questions and I really apprecaite all
the help.

Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>

<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwell</company>
<address>Street Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>

<!-- Next product here-->
</products>
I am loading the doc in memory using xmlDocument
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)
End Sub

Here is when my problem starts. I have a form with all the information
that
I needed "appended" to the XMLdoc (in memory). I tried

Private Sub AddProduct(ByVal node As XmlNode)
Dim xmlProductName = txtProduct.Text
Dim xmlCompanyName = txtCompany.Text
Dim xmlAddress = txtAddress.Text
Dim xmlCity = txtCity.Text
Dim xmlState = cmboState.Text
Dim xmlZip = txtZip.Text
node.AppendChild(xmlProductName)
node.AppendChild(xmlCompanyName)
node.AppendChild(xmlAddress)
node.AppendChild(xmlCity)
node.AppendChild(xmlState)
node.AppendChild(xmlZip)
End Sub

But I am really confused on what node to pass. Any help would be
apprciated.


Jul 21 '05 #6

P: n/a
That would generally be caused by you not passing an XmlNode into the
method. Please can you put a breakpoint onto AddProduct(XmlNode node), and
let us know what runtime type is reported by VS.NET for the parameter being
passed in.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Here is my debug output.

'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorl ib.dll', No symbols
loaded.
'Zadig': Loaded 'C:\Documents and Settings\mlubrano\My Documents\Visual
Studio Projects\Zadig\bin\Zadig.exe', Symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.windows.forms\1.0.50 00.0__b77a5c561934e089\system.windows.forms.dll',
No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c56 1934e089\system.dll', No
symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5 000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll' ,
No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__ b03f5f7f11d50a3a\system.drawing.dll',
No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a 5c561934e089\system.xml.dll',
No symbols loaded.
An unhandled exception of type 'System.InvalidCastException' occurred in
Zadig.exe

Additional information: Specified cast is not valid.
Unhandled Exception: System.InvalidCastException: Specified cast is not
valid.
at Zadig.Products.AddProduct(XmlNode node) in C:\Documents and
Settings\mlubrano\My Documents\Visual Studio
Projects\Zadig\Products.vb:line
239
at Zadig.Products.bttnAdd_Click(Object sender, EventArgs e) in
C:\Documents and Settings\mlubrano\My Documents\Visual Studio
Projects\Zadig\Products.vb:line 223
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs 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.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Zadig.Zadig.Main() in C:\Documents and Settings\mlubrano\My
Documents\Visual Studio Projects\Zadig\Main.vb:line 3The program '[328]
Zadig.exe' has exited with code 0 (0x0).

"fremenusul" wrote:
Now I am getting this error

Additional information: Specified cast is not valid.

error begins on this line
node.AppendChild(xmlProductName)

Thanks for the help.

Michae
"Sean Hederman" wrote:
> Whoops! That was silly, rather do:
> AddProduct(xmlDoc.ChildNodes(0))
> It'll be faster than using XPath.
>
> "fremenusul" <fr********@discussions.microsoft.com> wrote in message
> news:79**********************************@microsof t.com...
> >I know I have been asking LOTS of xml questions and I really
> >apprecaite all
> > the help.
> >
> > Here is my XML file
> > <?xml version="1.0" encoding="utf-8" ?>
> >
> > <products>
> > <!-- Repeat the structure below for each product. -->
> > <product>
> > <id>CP-90, T-32</id>
> > <company>Carwell</company>
> > <address>Street Address</address>
> > <city>City</city>
> > <state>State</state>
> > <zip>Zip</zip>
> > </product>
> >
> > <!-- Next product here-->
> > </products>
> >
> >
> > I am loading the doc in memory using xmlDocument
> > Dim xmlFile As String = xmlLocation()
> > Dim xmlDoc As XmlDocument
> >
> > Private Sub Products_Load(ByVal sender As System.Object, ByVal e
> > As
> > System.EventArgs) Handles MyBase.Load
> > xmlDoc = New XmlDocument
> > xmlDoc.Load(xmlFile)
> >
> >
> > End Sub
> >
> > Here is when my problem starts. I have a form with all the
> > information
> > that
> > I needed "appended" to the XMLdoc (in memory). I tried
> >
> > Private Sub AddProduct(ByVal node As XmlNode)
> > Dim xmlProductName = txtProduct.Text
> > Dim xmlCompanyName = txtCompany.Text
> > Dim xmlAddress = txtAddress.Text
> > Dim xmlCity = txtCity.Text
> > Dim xmlState = cmboState.Text
> > Dim xmlZip = txtZip.Text
> > node.AppendChild(xmlProductName)
> > node.AppendChild(xmlCompanyName)
> > node.AppendChild(xmlAddress)
> > node.AppendChild(xmlCity)
> > node.AppendChild(xmlState)
> > node.AppendChild(xmlZip)
> > End Sub
> >
> > But I am really confused on what node to pass. Any help would be
> > apprciated.
>
>
>

Jul 21 '05 #7

P: n/a
Got the answer
(http://msdn.microsoft.com/newsgroups...9-5639e23d5cb4)

I do have another question about reading xml from memory though....
I am building a application that uses XML data to display prducts.

Currently, I have a class that holds the XML data.

Imports System.Xml

Public Class Settings

Private Shared xmlDoc As XmlDocument

Public Shared Property Products() As XmlDocument
Get
If xmlDoc Is Nothing Then
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)
End If

Return xmlDoc
End Get
Set(ByVal Value As XmlDocument)

End Set
End Property

End Class

Here is where my problem begins. I have a form that has a combobox that will
display some of the xml data. If someone needs to add data a new form pops up
and they add data to the memory (xml). Then it saves the new XML file.

If they close the "add products" form, the combobox is NOT updated with the
new information. How can I have the combobox read the XML data (in memory)?

PS: here is how I was doing it before I added a class to hold XML data.
Private Sub Zadig_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Dim xmlTr As New XmlTextReader(xmlFile)

'While xmlTr.Read
' If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
XmlNodeType.Element Then
' cmbProducts.Items.Add(xmlTr.ReadString)
' End If
'End While
'xmlTr.Close()

'xmlDoc = New XmlDocument
'xmlDoc.Load(xmlFile)

End Sub

I dont think I can do it in the "load" area because it is only loaded once.
I need something that will be "dynamic" with the combobox.

"Sean Hederman" wrote:
That would generally be caused by you not passing an XmlNode into the
method. Please can you put a breakpoint onto AddProduct(XmlNode node), and
let us know what runtime type is reported by VS.NET for the parameter being
passed in.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Here is my debug output.

'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorl ib.dll', No symbols
loaded.
'Zadig': Loaded 'C:\Documents and Settings\mlubrano\My Documents\Visual
Studio Projects\Zadig\bin\Zadig.exe', Symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.windows.forms\1.0.50 00.0__b77a5c561934e089\system.windows.forms.dll',
No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c56 1934e089\system.dll', No
symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5 000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll' ,
No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__ b03f5f7f11d50a3a\system.drawing.dll',
No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a 5c561934e089\system.xml.dll',
No symbols loaded.
An unhandled exception of type 'System.InvalidCastException' occurred in
Zadig.exe

Additional information: Specified cast is not valid.
Unhandled Exception: System.InvalidCastException: Specified cast is not
valid.
at Zadig.Products.AddProduct(XmlNode node) in C:\Documents and
Settings\mlubrano\My Documents\Visual Studio
Projects\Zadig\Products.vb:line
239
at Zadig.Products.bttnAdd_Click(Object sender, EventArgs e) in
C:\Documents and Settings\mlubrano\My Documents\Visual Studio
Projects\Zadig\Products.vb:line 223
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs 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.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Zadig.Zadig.Main() in C:\Documents and Settings\mlubrano\My
Documents\Visual Studio Projects\Zadig\Main.vb:line 3The program '[328]
Zadig.exe' has exited with code 0 (0x0).

"fremenusul" wrote:
Now I am getting this error

Additional information: Specified cast is not valid.

error begins on this line
node.AppendChild(xmlProductName)

Thanks for the help.

Michae
"Sean Hederman" wrote:

> Whoops! That was silly, rather do:
> AddProduct(xmlDoc.ChildNodes(0))
> It'll be faster than using XPath.
>
> "fremenusul" <fr********@discussions.microsoft.com> wrote in message
> news:79**********************************@microsof t.com...
> >I know I have been asking LOTS of xml questions and I really
> >apprecaite all
> > the help.
> >
> > Here is my XML file
> > <?xml version="1.0" encoding="utf-8" ?>
> >
> > <products>
> > <!-- Repeat the structure below for each product. -->
> > <product>
> > <id>CP-90, T-32</id>
> > <company>Carwell</company>
> > <address>Street Address</address>
> > <city>City</city>
> > <state>State</state>
> > <zip>Zip</zip>
> > </product>
> >
> > <!-- Next product here-->
> > </products>
> >
> >
> > I am loading the doc in memory using xmlDocument
> > Dim xmlFile As String = xmlLocation()
> > Dim xmlDoc As XmlDocument
> >
> > Private Sub Products_Load(ByVal sender As System.Object, ByVal e
> > As
> > System.EventArgs) Handles MyBase.Load
> > xmlDoc = New XmlDocument
> > xmlDoc.Load(xmlFile)
> >
> >
> > End Sub
> >
> > Here is when my problem starts. I have a form with all the
> > information
> > that
> > I needed "appended" to the XMLdoc (in memory). I tried
> >
> > Private Sub AddProduct(ByVal node As XmlNode)
> > Dim xmlProductName = txtProduct.Text
> > Dim xmlCompanyName = txtCompany.Text
> > Dim xmlAddress = txtAddress.Text
> > Dim xmlCity = txtCity.Text
> > Dim xmlState = cmboState.Text
> > Dim xmlZip = txtZip.Text
> > node.AppendChild(xmlProductName)
> > node.AppendChild(xmlCompanyName)
> > node.AppendChild(xmlAddress)
> > node.AppendChild(xmlCity)
> > node.AppendChild(xmlState)
> > node.AppendChild(xmlZip)
> > End Sub
> >
> > But I am really confused on what node to pass. Any help would be
> > apprciated.
>
>
>


Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.