how to read specific node in xml doc, example ""

I've never worked with xml but I need to get specific node from xml document.  In example above a need to get node 2 of node 0 of node 4 of node 1 and its attributes. Can somebody just point me where to look at least? Thanks in advance
You died at the very end of your life
6/8/2004 6:20:16 PM 7181 articles. 0 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 6

Hi exptrade,

Im not sure about your example but ive given you an example here of how to get a specific node and its attributes.
XmlDocumen doc = new XmlDocument("person.xml");
-person is the root node
<name fname="fez" lname="zef"></name>
<address>123 Abc Street</address>
so to get the fname and lname i would need to write
string p1 = doc.SelectSingleNode("/person/name").Attributes["fname"].InnerText
the same applies for lname
to get the element from address you would write
string a1 = doc.SelectSingleNode("/person/address").InnerText
here is a link on msdn docs for more info on XPath
All the best

There's a myth that if we were really good at programming, there would be no bugs to catch.

If my reply has answered your question, please mark the reply as "Answer".
6/8/2004 11:52:05 PM
thanks for replay. Here is what I had in mind and how I read it.

<treenode text="something" navigateurl="something"

And here is the code:
Dim myXmlDocument As XmlDocument = New XmlDocument
'nodeIdx is a string, example ""
Dim nodeArr As String() = nodeIdx.Split(CType(".", Char))
Dim node As XmlNode = myXmlDocument.DocumentElement
Dim nodes As XmlNodeList = node.ChildNodes
Dim idx As Integer
For idx = 1 To nodeArr.Length - 1
node = nodes(CInt(nodeArr(idx)))
nodes = node.ChildNodes
Dim fileName As String = CType(node.Attributes(0).Value, String)
Dim filePath As String = CType(node.Attributes(1).Value, String)

Now is this optimal way of doing this. Seems to me to be straight forward enough.
You died at the very end of your life
6/9/2004 1:41:48 PM
1) I hope you realize your XML is not well formed

2) this x-path expression gets you the attributes you want:
3) You can issue xpath expressions against an XmlDocument like this:
XmlDocument doc = new XmlDocument();
// this gets you the desired node
XmlNode node = doc.SelectSingleNode("/treenodes/treenode[2]/treenode[5]/treenode[3]");
// these are the desired attribute values.
string text = node.Attributes["text"].Value;
string navigateUrl = node.Attributes["navigateurl"].Value;
This code is not tested, just written from scratch, maybe it will need some changes, the idea is there though. If you're not familiar with xpath, I'd recommend
6/10/2004 9:06:46 AM
pa_li, thanks for your suggestion but something is not right. my node is always nothing. I don't know if xml is or is not well formed, it is the format that treeview requests. Here is a piece of xml doc itself. xml doc is created using xmlwriter

<?xml version="1.0" encoding="utf-8" ?>
<treenode text="SD1051.pdf" navigateurl="C:\Documents and Settings\epitka\My Documents\Visual Studio Projects\DotNetNuke_2.0.4\wfi_docs\CertDrw\SD1051.pdf" />
<treenode text="SD1051S.pdf" navigateurl="C:\Documents and Settings\epitka\My Documents\Visual Studio Projects\DotNetNuke_2.0.4\wfi_docs\CertDrw\SD1051S.pdf" />

You died at the very end of your life
6/10/2004 1:55:23 PM
this last xml is well formed

of course the node is nothing... You said you wanted to access the treenodes using their ordinal position, like node 1 of node 2 of node 4.
If you want to get all descendants of your treenodes element (the root), use this:
If you want to select only those with a navigateurl attribute (that would be the childless nodes), use this
Now you can iterate this collection to get both the text and navigateurl attributes
If this doesn't help you, specify exactly what you want to achieve....
6/10/2004 2:37:18 PM

Similar Artilces:

"Error loading XML file :\windows\\framework\v1.0.3705"...does this mean v.1.1 code trying to run in a v.1.0 app?
I uploaded some new files into my existing third-party hosted site, including a .DLL into \BIN\, which is running AS.NET v.1.0. I got the following error message when browsing to one of the pages using the code in the namespace defined in the DLL: Error loading XML file c:\windows\\framework\v1.0.3705\Config\machine.config Request for the permission of type System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. (c:\windows\\framework\v1.0.3705\Config\machine.config) ...

Parser Error
What do I make to solve that problem? Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Stream is not a valid resource file.Source Error: Line 1: <?xml version="1.0" encoding="utf-8" ?> Line 2: <locales> Line 3: <inactive>Source File: /dotnetnuke320/App_GlobalResources/Locales.Portal.xml.resources    Line: 1 Version Information: Microsoft .NET Framework Versio...

<?xml version="1.0" encoding="utf-8"?>
Is there a way to manually put this delcaration at the top of at xml document being built by c# XmlTextWriter directly from a dataset?  Right now, all I'm getting is <NewDataSet><Table>.... Thanks, Jody Yes, call xmlTextWriter.WriteStartDocument() before writing out a dataset. But I wonder why do you need it? It's optional declaration.Oleg [XML MVP, MCPD]XmlLab.Net | The application consuming the xml expects it (sometime).  I'll try your fix.  Thank you. that got it.  you're the man. j...

<?xml version="1.0" encoding="utf-8" ?>
Blank to all,I insert this fragment of code in order to ask to you if e´possibile to insert between the lines a code in order to copy file from one determined folder to an other and if e´possibile you could indicate some information to me since they are ignoring in matter?<?xml version="1.0" encoding="utf-8" ?><Button ID="APAGAR"><Left>60</Left><Top>65</Top><Width>70</Width><Height>76</Height><Image>skin\Apagar\ApagarPP.png</Image><ImagePressed>Skin\Apagar\ApagarP.png</ImagePre...

<?xml version="1.0" encoding="utf-8" ?>
Hi, my web service returns this when generating a web method xml code. However, between the last " of the UTF-8 and the ? there is a space. When I build and debug my web service, it runs fine, but if I attempt to acces my web service through the browser on my localhost, this - <?xml version="1.0" encoding="utf-8" ?>   - does not appear, instead appears a message like this:  The XML document is not associated with styles. The document structure is representes above. (the original message is ir Portuguese, I've only translated!)And the rest o...

ff1.5.0.4 user.js needs fix to "stick" user_pref("network.proxy.ssl", "");
Intro: When i install a new version of ff, I manually set options for one basic profile. Then I copy certain prefs into a user.js that is copied into all profiles. The proxomitron settings are Connection settings in the user.js As stored in prefs.js of previous version of FF ( profiles, these are the "correct" connection settings: user_pref("network.proxy.http", ""); user_pref("network.proxy.http_port", 8080); user_pref("network.proxy.ssl", ""); user_pref("network.proxy.ssl_port", 8...

.Net 1.1 with .Net 2.0 virtual directory using AJAX "Sys undefined"
I'm having an issue running an AJAX app I built, I think I might know what the problem might be, but if so, I am not sure how to fix it. The main site is built with 1.1 and new application is 2.0.  I have the new application configured properly (as far as I can tell) in its own app pool, etc..  The app runs just fine (I have other 2.0 apps that run along side the main 1.1), but I am getting an error: "Sys undefined...."  I've checked to enusre the mappings for the .axd extension for this particular VD are pointing to the correct place as ...

New Install: <?xml version="1.0" encoding="UTF-8" ?> error
Hi,I'm new to .net.  I'm trying to install DotNetNuke on my XP Pro with IIS 5.0 box.  I've made all the changes to web.config, created the db with permissions and I'm still getting the same error.Can't figure it out!Here's the error:  Server Error in '/DotNetNuke' Application. Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Stream is not a valid resource file.Source Error: Line 1...

Migration from .net 1.1 to .net 2.0 and deployed in server: error "Server Application Unavilable"
Hi, I have upgraded one .net 1.1 application to .net 2.0. though locally the application is running fine, when deployed in the server it is giving the following error : Server Application Unavailable The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request. Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused thi...

Book Review of "A First Look at ADO.NET and System.Xml v. 2.0"
Hello, I have got chance to review "A First Look at ADO.NET and System.Xml v. 2.0" book! Have a look my review @ Hope my review helps you! Sreedharhttp://www.w3coder.orgweblog

We load and save files with XMLDocument and FastReport 4.7. I get an error message: Invalid version number, <?xml version=""1.1" encoding="utf-8"?> Is 1.1 a valid XML version? If version 1.1 is valid, when will XMLDocument be able to handle it? Larry. "Larry Griffiths" <> wrote in message > Is 1.1 a valid XML version? Technically yes: > If version 1.1 is valid, when will XMLDocument be able to handle it? ...

RE: [perl #18114] [no subject] BUG: "-4\n".."0\n" is not DWIM but "-4\n".."-0\n" is!
------_=_NextPart_001_01C28007.C953E480 Content-Type: text/plain; charset="iso-8859-1" >> J Kimball (via RT) on Tuesday, October 29, 2002 8:49 AM >> On Mon, Oct 28, 2002 at 08:18:24AM -0000, >> (via RT) wrote: >> >> > I wrote the following program: >> > >> > $w1=<STDIN>; >> > $w2=<STDIN>; >> > @numlist = ($w1 .. $w2); >> > print @numlist; >> > >> > [run] >> > -4 (first input) >> > 0 (second input) >> > >>...

RE: [perl #18114] [no subject] BUG: "-4\n".."0\n" is not DWIM but "-4\n".."-0\n" is!
------_=_NextPart_001_01C28029.B9C8E340 Content-Type: text/plain; charset="iso-8859-1" Slaven Rezic Sent on 30 October 2002 16:23 > There is a special handling for numeric strings beginning with a "0". > This is to allow things like "01".."31" to preserve the leading zero > for one-digit numbers. Aha! > > The special handling is triggered if either the left or right operand > starts with "0". For left operands this is OK but I cannot think of a > useful case where only a right operand with leading zero t...

.NET 1.1 to 2.0 "remember me" checkbox no longer works
I have a site I recently updated to ASP.NET 2.0 from 1.1 and everything works fine (with minimal fiddling) except the remember me check box on the log in page.  I use custom forms authentication.  Web.config defines the timeout as 60 minutes: <forms name="NIDB1AuthCookie" protection="All" timeout="1" loginUrl="Login.aspx" cookieless="UseCookies" />And in the login.aspx.cs file I have it check the checkbox to see if its checked and then manually set the cookie to expire in 30 days.  if (cbRememberMe.Checked){ //Set cookie to expire in 30 days if user checks the remem...

Web resources about - how to read specific node in xml doc, example "" -

Specific - Wikipedia, the free encyclopedia
Specific Pathogen Free , of a laboratory animal guaranteed free of particular (i.e., specific and named) pathogens "Specific" generally means ...

Specific activity - Wikipedia, the free encyclopedia
... SI quantity related to the phenomenon of natural and artificial radioactivity. The SI unit of "activity" is becquerel, Bq, while that of "specific ...

Facebook Displays Percent Of Users Who Like Pages Who Have Seen Specific Posts
Facebook continues to quietly add and tweak features behind-the-scenes, without fanfare or announcements, and the latest example is the addition ...

Navy Football to Feature Position-Specific 'Navy Fleet' Helmets for Army Game - Bleacher Report
For the first time in NCAA history, a college football team will have its players wearing different helmets during the game based on the position ...

"So the product is being deliberately misused despite a specific warning label, and y'all are complaining ...
"Nobody was irreparably broken or even like stubbed their toe? BURN BUNCH EMS DOWN. Bomb this company back to the stone age before the hair of ...

Nashua Public Schools Closed Following ‘Specific’ Threat Of Violence
All public schools in Nashua, NH, will be closed Monday after school officials received a detailed threat of violence involving the city's two ...

Obama: No specific, credible threat indicating plot against U.S.
After a meeting with his national security team, the president tells Americans to "go about their usual Thanksgiving weekend activities"

Tesla Seatbelt Recall Specifics, & Video On How To Check Your Seatbelt Yourself
... of a Model S in Europe with a seatbelt that wasn’t properly attached to the outboard lap pretensioner. [&hellip Tesla Seatbelt Recall Specifics, ...

Obama: No 'specific and credible threat' to U.S. -
... step" to keep the country safe, President Barack Obama said Wednesday, seeking to reassure travelers and adding there is no known "specific ...

NY Fast-Food Specific Wage Hike Clears Appeal
Fast food workers in New York take a step closer to a $15 minimum wage.

Resources last updated: 12/22/2015 12:51:50 PM