473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

How to find first XML occurrence of <elementName> via SelectSinglenode?

Hi,

Last question (promise). I want to write out a new XML row, tacked onto
the end of everything contained under the first <elementNamesection.
I can do the write, I'm just not sure what the xpath is to complete the
following:

XmlElement el = (XmlElement)cdjDoc.SelectNodes(@"first element named
elementName");

Can anyone tell me?

Thanks a jillion - i'll go away now :)

Nov 30 '06 #1
5 11217
sherifffruitfly wrote:
Hi,

Last question (promise). I want to write out a new XML row, tacked onto
the end of everything contained under the first <elementNamesection.
I can do the write, I'm just not sure what the xpath is to complete the
following:

XmlElement el = (XmlElement)cdjDoc.SelectNodes(@"first element named
elementName");

Can anyone tell me?

Thanks a jillion - i'll go away now :)
Without knowing your full XML document, it sounds like you want to use a
positional predicate to get the first node. Using your Soldiers example
from earlier, if you wanted to select the first Soldier under Soldiers you
would use the following:

XmlNode firstSoldier = xDoc.SelectSingleNode("Soldiers/Soldier[1]");
--
Tom Porterfield

Nov 30 '06 #2
Hello!

XmlNode firstSoldier = xDoc.SelectSingleNode("Soldiers/Soldier");

Actually, you don't need to specify the indexer as XmlNode.SingleNode
returns the first node if the query results in a XmlNodeList. I like the
explicit query, but I think its worth knowing there's another way to write
the query :-)

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)
Nov 30 '06 #3

Anders Borum wrote:
Hello!

XmlNode firstSoldier = xDoc.SelectSingleNode("Soldiers/Soldier");

Actually, you don't need to specify the indexer as XmlNode.SingleNode
returns the first node if the query results in a XmlNodeList. I like the
explicit query, but I think its worth knowing there's another way to write
the query :-)
Ack - this assumes what I previously said about the structure of my XML
document. I have since found out that there are a few different formats
that my XML files could be in, and the <Soldierssection could be in a
few different places.

I need to obtain the first <Soldierselement *wherever* it may lie in
the XML document - with no assumptions being made about the document's
structure.

Sorry I didn't say explicitly that I've had to give up my assumptions
about the XML files.

But thanks for the answers!

cdj

Dec 1 '06 #4
It's
XmlNode firstSoldier = xDoc.SelectSingleNode("//Soldier");

hth

"sherifffruitfly" <sh*************@gmail.comschrieb im Newsbeitrag
news:11*********************@l12g2000cwl.googlegro ups.com...
>
Anders Borum wrote:
>Hello!

XmlNode firstSoldier = xDoc.SelectSingleNode("Soldiers/Soldier");

Actually, you don't need to specify the indexer as XmlNode.SingleNode
returns the first node if the query results in a XmlNodeList. I like the
explicit query, but I think its worth knowing there's another way to
write
the query :-)

Ack - this assumes what I previously said about the structure of my XML
document. I have since found out that there are a few different formats
that my XML files could be in, and the <Soldierssection could be in a
few different places.

I need to obtain the first <Soldierselement *wherever* it may lie in
the XML document - with no assumptions being made about the document's
structure.

Sorry I didn't say explicitly that I've had to give up my assumptions
about the XML files.

But thanks for the answers!

cdj

Dec 1 '06 #5

Christof Nordiek wrote:
It's
XmlNode firstSoldier = xDoc.SelectSingleNode("//Soldier");

hth
It helped very much - thanks for the help everyone!

cdj

Dec 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
7
by: Anders S. Clausen | last post by:
Hi I have a jsp with a couple of <HTML:TEXTAREA> where I would like to dynamically size the textarea depending on the length of a String entered on a different jsp. The two new textareas are to...
1
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
5
by: MLibby | last post by:
How can you tell when you've reached an elements end tag? For example, how can the following code tell that <MenuItem Label="Overview" ClientSideOnClick="CacheDemo/IntroToCache.ascx"/> has an end...
0
by: Michael Jackson | last post by:
I have attempted to mark up a service and it's methods so that it doesn't require the SOAPAction HTTP header to resolve the methods being called, this is done from first element in <SOAP-ENV:Body>...
0
by: jimmyfishbean | last post by:
Hi, I have a successful VB6 web service client that uses the SOAP Toolkit 3 to make calls to a web service written in ASP.Net (VB.Net). However, due to Microsoft not recommending the use of...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.