?
Solved

Referencing XML nodes?

Posted on 2004-03-26
2
Medium Priority
?
253 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 375 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

Independent Software Vendors: 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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 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