Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPath Concat() Function

Status
Not open for further replies.

Thedj2222

Programmer
Jan 23, 2008
1
GB
Hi everyone,

I need some help using XPath to retrieve data from an XML file. The example XML is below:

<Date>
<Year>2008</Year>
<Month>02</Month>
<Day>01</Day>
</Date>

I am using VB.NET to execute the XPath, so it will look something like:

... XPathNavigator.Select("/Date[concat(day, month, year)]")

No matter what i have tried, all i can get it to return is '20080201', which is in the wrong format (i.e. it should return '01022008').

In fact, it doesnt matter what i put in the concat function (e.g. it could be [concat(blah, blah, blah)], it would still return '20080201'. It appears to be just reading the text values of its child nodes.

My questions are:

1. Is the Concat function capable of doing what i need it to do (i.e. concatenating nodes in a particular order)? If so, where am i going wrong?

2. If the Concat function is not capable of this, how can i achieve what i want to do?

Thank you for any help you can give.

Rich
 
Rich,

Your first clue might have been that, since XML (and therefore XPath) is case sensitive, your example of [tt]Date[concat([COLOR=blue white]d[/color]ay, [COLOR=blue white]m[/color]onth, [COLOR=blue white]y[/color]ear)]"[/tt] might not return anything useful.

Have you tried the following XPath expression?
Code:
concat(Date/Day, Date/Month, Date/Year)

In general, when you have square brackets it is a predicate that is used to constrain the choice of nodes at that particular point in the expression. For example, [tt]//Date[Year = '2008'] [/tt]would select all the Date nodes that have a subordinate Year element the value of which is 2008.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top