473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

xmlnode question

NS
Hello,
I'm new to xml and I have a question:

I try to do the following
Dim doc As New XmlDocument
doc.LoadXml("<Request><Root><Requestor name='' /><FlowData flowstatus=''
/><Products><productdate productid='' /></Products></Root></Request>")

Dim node As XmlNode =
doc.SelectSingleNode("Request/Root/Requestor/@name")

node.Value = "TestValue"
Dim node3 As XmlNode =
doc.SelectSingleNode("Request/Root/FlowData/@flowstatus")

node3.Value = "TestStatus"

'here comes something I don't know how to do, I want to fill in multiple
products

Dim i As Integer = 1
Dim node2 As XmlNode
For i = 1 To 3

node2 =
doc.SelectSingleNode("Request/Root/Products/productdate/@productid")
node2.Value = i

i = i + 1
Next i
Finally I take the innerxml to do further operations.

The problem is that the value for node2 always get overwritten. I want a
loop that fills x number of products.

Any suggestions ?

Regards,
Oct 12 '06 #1
2 1640


NS wrote:

Dim doc As New XmlDocument
doc.LoadXml("<Request><Root><Requestor name='' /><FlowData flowstatus=''
/><Products><productdate productid='' /></Products></Root></Request>")
Dim i As Integer = 1
Dim node2 As XmlNode
For i = 1 To 3

node2 =
doc.SelectSingleNode("Request/Root/Products/productdate/@productid")
node2.Value = i

i = i + 1
Next i
The problem is that the value for node2 always get overwritten. I want a
loop that fills x number of products.
Well your XML above does not have several products elements but only one
and only once productdate element. If you want to add elements to an
XmlDocument then you need to first create them and then insert as needed
e.g.
Dim Products As XmlNode = doc.SelectSingleNode("Request/Root/Products")
For I = 2 To 3
Dim ProductDate As XmlElement = doc.CreateElement("productdate")
ProductDate.SetAttribute("productid", I.ToString())
Products.AppendChild(ProductDate)
Next

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 12 '06 #2
NS

"Martin Honnen" <ma*******@yahoo.deschreef in bericht
news:uH**************@TK2MSFTNGP03.phx.gbl...
>
Well your XML above does not have several products elements but only one
and only once productdate element. If you want to add elements to an
XmlDocument then you need to first create them and then insert as needed
e.g.
Dim Products As XmlNode = doc.SelectSingleNode("Request/Root/Products")
For I = 2 To 3
Dim ProductDate As XmlElement = doc.CreateElement("productdate")
ProductDate.SetAttribute("productid", I.ToString())
Products.AppendChild(ProductDate)
Next

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thank you very much ! Do you have any tips suggestions to read my
xmldocument into a dataset ?
Dim doc As New XmlDocument
doc.LoadXml("<Request><Root><Requestor name='' /><FlowData flowstatus=''
/><Products><productdate productid='' /></Products></Root></Request>")
Or any other suggestions so that I can manipulate data ?
e.g. I want to build a webform with a detail table with all the products
from my xmldocument.

Regards,
NS
Oct 13 '06 #3

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

Similar topics

5
by: Ian Williamson | last post by:
Greetings, I have seen this question posted a few times, but the answers have not helped me. I have used the program xsd.exe to generate several c# classes from a client provided xsd...
9
by: JJ | last post by:
Hi All, I noticed that XmlNode and XpathNavigator are quite similiar. XmlNode seems to navigate over an XML Doc and so does XPathNav so when do I use XPathNavigator instead of XmlNode? ...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
1
by: Owen Blacker | last post by:
An awkward question. In a CMS-like environment, I have a list of items that is generated on the serverside using an XmlDocument to throw together XHTML tags (mainly because it's substantially...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
4
by: jens Jensen | last post by:
Hello, I have built a client of a websevrice. I call a webmethod that takes an Xmldocument object and returns an Xmldocument object. When i add a refernce to this webservice on the client, then...
5
by: GaryDean | last post by:
I have a web service method that returns an XMLDocument. The signature is: public XmlDocument GetPOs() The following client code calls this method but it accepts an XMLNode instead of an...
5
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.