473,569 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Append XML Child Node (Additional problems)

I orginally asked this question on friday, and made some progress, but now I
am getting an error.

What is the type of xmlProductName (check the runtime type in the debugger)?

The debug output is as follows.

'DefaultDomain' : Loaded
'c:\winnt\micro soft.net\framew ork\v1.1.4322\m scorlib.dll', No symbols loaded.
'Zadig': Loaded 'C:\Documents and Settings\mlubra no\My Documents\Visua l
Studio Projects\Zadig\ bin\Zadig.exe', Symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assem bly\gac\system. windows.forms\1 .0.5000.0__b77a 5c561934e089\sy stem.windows.fo rms.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assem bly\gac\system\ 1.0.5000.0__b77 a5c561934e089\s ystem.dll', No
symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assem bly\gac\microso ft.visualbasic\ 7.0.5000.0__b03 f5f7f11d50a3a\m icrosoft.visual basic.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assem bly\gac\system. drawing\1.0.500 0.0__b03f5f7f11 d50a3a\system.d rawing.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assem bly\gac\system. xml\1.0.5000.0_ _b77a5c561934e0 89\system.xml.d ll', No symbols loaded.
An unhandled exception of type 'System.Invalid CastException' occurred in
Zadig.exe

Additional information: Specified cast is not valid.
Unhandled Exception: System.InvalidC astException: Specified cast is not valid.
at Zadig.Products. AddProduct(XmlN ode node) in C:\Documents and
Settings\mlubra no\My Documents\Visua l Studio Projects\Zadig\ Products.vb:lin e
239
at Zadig.Products. bttnAdd_Click(O bject sender, EventArgs e) in
C:\Documents and Settings\mlubra no\My Documents\Visua l Studio
Projects\Zadig\ Products.vb:lin e 223
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth ods+IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at Zadig.Zadig.Mai n() in C:\Documents and Settings\mlubra no\My
Documents\Visua l Studio Projects\Zadig\ Main.vb:line 3The program '[328]
Zadig.exe' has exited with code 0 (0x0).
"fremenusul " <fr********@dis cussions.micros oft.com> wrote in message
news:40******** *************** ***********@mic rosoft.com...
Now I am getting this error

Additional information: Specified cast is not valid.

error begins on this line
node.AppendChil d(xmlProductNam e)

Thanks for the help.

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

"fremenusul " <fr********@dis cussions.micros oft.com> wrote in message
news:79******** *************** ***********@mic rosoft.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>Carwel l</company>
> <address>Stre et 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(B yVal sender As System.Object, ByVal e As
> System.EventArg s) Handles MyBase.Load
> xmlDoc = New XmlDocument
> xmlDoc.Load(xml File)
>
>
> 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(ByVa l 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.AppendChil d(xmlProductNam e)
> node.AppendChil d(xmlCompanyNam e)
> node.AppendChil d(xmlAddress)
> node.AppendChil d(xmlCity)
> node.AppendChil d(xmlState)
> node.AppendChil d(xmlZip)
> End Sub
>
> But I am really confused on what node to pass. Any help would be
> apprciated.



Nov 22 '05 #1
2 2456
Here is my complete code.

Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xml File)
End Sub

Private Sub bttnAdd_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles bttnAdd.Click
AddProduct(xmlD oc.ChildNodes(0 ))
'xmlDoc.Save(". .\xmldoc.xml")
End Sub

Private Sub btnClose_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnClose.Click
xmlDoc.Save(".. \xmldoc.xml")
Me.Close()
End Sub

Private Sub AddProduct(ByVa l 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.AppendChil d(xmlProductNam e)
node.AppendChil d(xmlCompanyNam e)
node.AppendChil d(xmlAddress)
node.AppendChil d(xmlCity)
node.AppendChil d(xmlState)
node.AppendChil d(xmlZip)
End Sub
Nov 22 '05 #2
After MUCH research I found a solution

http://support.microsoft.com/default...b;en-us;317665

Very well done article and it shows some good ways to update your document.
"fremenusul " wrote:
Here is my complete code.

Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xml File)
End Sub

Private Sub bttnAdd_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles bttnAdd.Click
AddProduct(xmlD oc.ChildNodes(0 ))
'xmlDoc.Save(". .\xmldoc.xml")
End Sub

Private Sub btnClose_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnClose.Click
xmlDoc.Save(".. \xmldoc.xml")
Me.Close()
End Sub

Private Sub AddProduct(ByVa l 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.AppendChil d(xmlProductNam e)
node.AppendChil d(xmlCompanyNam e)
node.AppendChil d(xmlAddress)
node.AppendChil d(xmlCity)
node.AppendChil d(xmlState)
node.AppendChil d(xmlZip)
End Sub

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1853
by: fremenusul | last post by:
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>
2
302
by: fremenusul | last post by:
I orginally asked this question on friday, and made some progress, but now I am getting an error. What is the type of xmlProductName (check the runtime type in the debugger)? The debug output is as follows. 'DefaultDomain': Loaded 'c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded. 'Zadig': Loaded...
3
1871
by: J Krugman | last post by:
This question refers to the DOM. I would like to dynamically append some small amount of text to the all-text content of a <pre> node. I suppose that I could extract the existing content, and replace the <pre> node in question with a new <pre> node that has the extended content. But the existing content is longish, and it seems to me...
2
1658
by: Scott | last post by:
hi friend's, i m new in both things php and in this group. but i have some basic knowledge of php and DOM in php. here is my problem, i have one textfield for add a new main node (not main like: <root><this_one></this_one></root>) in my php page and i m able to save the xml file correct with this, and in the bottom of that i have one new...
3
23940
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
10
2634
by: Rich Wallace | last post by:
I'm sure there's a very weasy way to do this, I've been running hard and fast on several things at once and just may be at the point of overthinking this... I receive an incoming XML document via a string feed within a web service: <Root> <Product> <File>Order</File> <Origin>OregonOffice</Origin>
1
2319
by: Daniel Rucareanu | last post by:
Hello, Does anybody knows how can you delete, in just one step, not using a loop, a subset of the child nodes of a given DOM parent node? The subset will be continous, so for example, if the parent node has 100 nodes, I want to delete nodes 10 through 75, and not nodes 5, 10, 25 etc. I have a reference to the first and the last node in...
4
3410
by: glbdev | last post by:
Hi, I posted this in "microsoft.public.xml.msxml-webrelease" but now realize it should probably have been in the ASP group. Sorry if that causes any problems. I have an XML document like: <MainNode> <Value>First Value</Value> </MainNode>
1
2254
by: harshaldhote | last post by:
Hello, I have created the xml Document through the C# application using XmlTextWriter Class, Which is as bellow, <?xml version="1.0" encoding="utf-8" ?> - <!-- Author HarshaL K. Dhote --> - <Project Location="C:\WorkSpace"> - <Cars>
1
34204
by: cleary1981 | last post by:
Hi All, Im sure its possible, every time I create a new element and add it to a node it becomes the last child. a=appendChild(object); How do I append a child to be the first node?
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.