XPath first node

Posted on 2006-06-21
Last Modified: 2012-06-27
I'm using xpath to analyze xml file.

this is my xml:

            <title lang="eng">Harry Potter</title>
            <title lang="eng">Learning XML</title>

I use the following xpath:

it fails becouse I have more then one node of that type. How do I ask for the first node?
Question by:aquasw
  • 2
LVL 60

Expert Comment

by:Geert Bormans
ID: 16951707
Hi aquasw,
> string(/bookstore/book/title[@lang="eng"])



Author Comment

ID: 16951864
I used this option, but get the error message "Too many items - string"
LVL 60

Accepted Solution

Geert Bormans earned 500 total points
ID: 16952546

do you have multiple bookstore or book elements?

then you need

it is likely that you don't need to cast to a string
since it will only work if the title is string content

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# advanced xml like string split - Help needed 15 73
Formatting an Excel formula to give correct date format 4 72
XML & .net 5 40
Excel file not created as expected 7 46
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now