Solved

Referencing XML nodes?

Posted on 2004-03-26
2
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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