Solved

Referencing XML nodes?

Posted on 2004-03-26
2
251 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

624 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