.NETGURU
XPath Question
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngxml' list.


Little, Ambrose
Is there a way to select just the top 1 of certain child elements. For
instance, let's say I've got a customer who can have one or more addresses
and one or more accounts. How would I form the XPath query to select the
customer and just the top 1 address and top 1 account?

Thanks.

--Ambrose

******************************************************************************
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
*******************************************************************************

Reply to this message...
 
    
Dan Wahlin
You can use the position() function for this.

Select the first customer's first address child node:

/Customers/Customer[position()=1]/Address[position()=1]

which can be simplified to the following:

/Customers/Customer[1]/Address[1]

You can do the same thing for other child elements when you need just
the first one. To select the last child when they repeat you can use
the last() function:

/Customers/Customer[1]/Address[position()=last()]

HTH,
Dan Wahlin

Wahlin Consulting LLC
Microsoft MVP - ASP.NET
http://www.XMLforASP.NET
XML for ASP.NET Developers by Dan Wahlin in bookstores everywhere!

-----Original Message-----
From: Little, Ambrose [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 25, 2002 10:05 AM
To: aspngxml
Subject: [aspngxml] XPath Question

Is there a way to select just the top 1 of certain child elements. For
instance, let's say I've got a customer who can have one or more
addresses
and one or more accounts. How would I form the XPath query to select
the
customer and just the top 1 address and top 1 account?

Thanks.

--Ambrose

************************************************************************
******
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
************************************************************************
*******

| [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.377 / Virus Database: 211 - Release Date: 07/15/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.377 / Virus Database: 211 - Release Date: 07/15/2002

Reply to this message...
 
    
Little, Ambrose
Okay, I'm trying something like this using XML templates and schemas w/
SQLXML.

Here's my template:
<?xml version="1.0" encoding="utf-8" ?>
<EproCustomer xmlns:sql="urn:schemas-microsoft-com:xml-sql">
    <sql:header>
        <sql:param name='CustomerId'></sql:param>
    </sql:header>
    <sql:xpath-query mapping-schema="../Schemas/EproCustomer.xdr">
        /Customer[@Id=$CustomerId]/child[1]
    </sql:xpath-query>
</EproCustomer>

I'm getting the following error:
<?xml version="1.0" encoding="utf-8" ?>
- <EproCustomer xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<?MSSQLError HResult="0x80004005" Source="Microsoft XML Extensions to SQL
Server" Description="XPath: positional predicates are not supported"?>
</EproCustomer>

Am I to understand that I cannot do this w/ SQLXML, or am I forming my query
incorrectly?

Thanks!

--Ambrose

[Original message clipped]

******************************************************************************
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
*******************************************************************************

Reply to this message...
 
    
Tim Curtin
x = oXMLDoc.SelectSingleNode("//myElement").childNodes(0).text

[Original message clipped]

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Reply to this message...
 
    
Dan Wahlin
Good question....here's a post I found on Google that says position() is
not supported in SQLXML (watch for wrapping) unfortunately:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=uelC
OFJxBHA.1772%40tkmsftngp07&rnum=9&prev=/groups%3Fq%3Dsqlxml%2Bposition()
%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DuelCOFJxBHA.1772%2
540tkmsftngp07%26rnum%3D9

Dan

Wahlin Consulting LLC
Microsoft MVP - ASP.NET
http://www.XMLforASP.NET
XML for ASP.NET Developers by Dan Wahlin in bookstores everywhere!

-----Original Message-----
From: Little, Ambrose [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 25, 2002 10:46 AM
To: aspngxml
Subject: [aspngxml] RE: XPath Question

Okay, I'm trying something like this using XML templates and schemas w/
SQLXML.

Here's my template:
<?xml version="1.0" encoding="utf-8" ?>
<EproCustomer xmlns:sql="urn:schemas-microsoft-com:xml-sql">
    <sql:header>
        <sql:param name='CustomerId'></sql:param>
    </sql:header>
    <sql:xpath-query mapping-schema="../Schemas/EproCustomer.xdr">
        /Customer[@Id=$CustomerId]/child[1]
    </sql:xpath-query>
</EproCustomer>

I'm getting the following error:
<?xml version="1.0" encoding="utf-8" ?>
- <EproCustomer xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<?MSSQLError HResult="0x80004005" Source="Microsoft XML Extensions to
SQL
Server" Description="XPath: positional predicates are not supported"?>
</EproCustomer>

Am I to understand that I cannot do this w/ SQLXML, or am I forming my
query
incorrectly?

Thanks!

--Ambrose

[Original message clipped]

************************************************************************
******
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
************************************************************************
*******

| [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.377 / Virus Database: 211 - Release Date: 07/15/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.377 / Virus Database: 211 - Release Date: 07/15/2002

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification