473,941 Members | 10,221 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

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

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

Can anyone tell me?

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

Nov 30 '06 #1
5 11276
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 <elementNamesec tion.
I can do the write, I'm just not sure what the xpath is to complete the
following:

XmlElement el = (XmlElement)cdj Doc.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.SelectSing leNode("Soldier s/Soldier[1]");
--
Tom Porterfield

Nov 30 '06 #2
Hello!

XmlNode firstSoldier = xDoc.SelectSing leNode("Soldier s/Soldier");

Actually, you don't need to specify the indexer as XmlNode.SingleN ode
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.SelectSing leNode("Soldier s/Soldier");

Actually, you don't need to specify the indexer as XmlNode.SingleN ode
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 <Soldierssectio n could be in a
few different places.

I need to obtain the first <Soldierselemen t *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.SelectSing leNode("//Soldier");

hth

"sherifffruitfl y" <sh************ *@gmail.comschr ieb im Newsbeitrag
news:11******** *************@l 12g2000cwl.goog legroups.com...
>
Anders Borum wrote:
>Hello!

XmlNode firstSoldier = xDoc.SelectSing leNode("Soldier s/Soldier");

Actually, you don't need to specify the indexer as XmlNode.SingleN ode
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 <Soldierssectio n could be in a
few different places.

I need to obtain the first <Soldierselemen t *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.SelectSing leNode("//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
2475
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 information for element <elementName>... I would appreciate if anyone could advice where I am going wrong. TIA Here's my xsd:
7
12633
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 display the full text (and no scroll bars), and I was wondering what I set the row and cols to .... keeping in mind that I have the length of the text I want to display. Any ideas??? Cheers.
1
27920
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 the filename, not the path, which is necessary in my situation. I cracked the problem in Firefox:
16
9577
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> ....... ....... </ArrayOfClassname>
5
5053
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 tag? StringBuilder sb = new StringBuilder(); if (xmlReader.NodeType == XmlNodeType.Element) { while (xmlReader.MoveToNextAttribute()) { sb.Append (xmlReader.Name + "=" + xmlReader.Value); // How can I tell when the end tag "/>" is reached ? ?...
0
2303
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> and the request and responses are not suffixed with Request and Response. Is there some more I could do with the attributes on the class that defines the WS and on the methods. the code for the WS etc is below. This I can get to work POST...
0
4614
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 SOAP Toolkit 3 on a Windows 2003 server, I must scrap the use of the toolkit and look to develop the client in VB.Net instead. I have upgraded the VB6 application to VB.Net using the built-in upgrade tool that comes with Visual Studio .Net 2003. ...
16
3546
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 and then query for the root element, the result is always null (1). However if I strip the root element of all attributes generated by XmlSpy, then there is no problem to find the root element with .NET XML classes (2). (1) The XML for which...
5
13414
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
10134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9964
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11296
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9858
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6298
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4450
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.