Solved

Referencing XML nodes?

Posted on 2004-03-26
2
249 Views
Last Modified: 2010-04-15
Hi,

This seems like it should be a straight forward question...

I just basically want to do DOM programming in C#, but I can't seem to find the methods I am familiar with from Javascript. I don't have much experience with this.

I want to access specific nodes of an xml document with array type notation as in child[1].child[1]. Actually, I think I need to do this with variables as in child[int].child[int].

my xml document looks something like this

<root>
   <items>
      <item/>
      <item/>
      <item/>
   </items>
  <items>
      <item/>
      <item/>
      <item/>
   </items>
  <items>
      <item/>
      <item/>
      <item/>
   </items>
</root>

 now imagine that I had an array string[] where I wanted to set the contents of string[] to the item values of one of those items elements such that...

string[] string = {"test1", "test2", "test3"};

ends up as

<items>
   <item>test1<item/>
   <item>test2<item/>
   <item>test3<item/>
<items/>



I am thinking something like

for(i=0; i<number;i++){
   XmlclassInstance.root.items[3].item[i] = string[i];
}

Does this make sense to anyone? Can anyone write a little piece of code instantiating the appropriate class instance using the right methods, with the right namespace declaration if non-standard? If I have this much I think I can figure out how to deal with looping the correct number of times and the other oddities of my real situation.

So far I have just been bumbling around with XPath, XPathNavigator, XmlDocument, but these don't seem to give me access to the members I need.

Thanks a lot in advance!

0
Comment
Question by:coltrane2003
2 Comments
 
LVL 2

Accepted Solution

by:
sedmans earned 125 total points
ID: 10686369
Try using the ChildNodes property instead of the Items.  Check out this MSDN article.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlNodeClassChildNodesTopic.asp
0
 
LVL 2

Author Comment

by:coltrane2003
ID: 10690488
Thanks sedmans! This is just what I needed.

I guess it is too elementary to be covered by my book. This is important because I don't think XPath or XPathNavigator allow you to write an expression with variables.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Greetings C# program 17 127
Problem!!! 8 37
IEnumerable<T> to a List<T> 8 40
need to convert function to c# 5 31
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question