Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath for selecting the text of an attribute

Reply
Thread Tools

XPath for selecting the text of an attribute

 
 
pjvleeuwen@gmail.com
Guest
Posts: n/a
 
      05-19-2008
Hi all,

For many of you this may be childishly simple, but the following
problem keeps me wondering for almost two hours, so I hope any of you
could point out what it is that I am doing wrong.

Consider the following simple XML: <?xml version="1.0"?
><rootE><tagA>valueA</tagA><tagB attrB1="attrValueB1"

attrB2="attrValueB2"/><tagC><tagCA/><tagCB/><tagCC><tagCCA/><tagCCA/
><tagCCB>60</tagCCB><tagCCC/></tagCC><tagCD/><tagCE/></tagC></rootE>


Now I want to read the value "attrValueB2" so I tried writing a
regular expression for it. I know that the following selects the
attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
@attrB2
But I cant seem to select the value of this attribute. I get an empty
string when quering /rootE/tagB/@attrB2/text()

ANY suggestions? I cant see what I'm doing wrong. Everything seems to
be fine in comparison with the tutorials I have seen and I tried all
the lexical variations / alterations I could think of.

Many thanks in advance for any suggestions!

Cheers,
Paul
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-19-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Now I want to read the value "attrValueB2" so I tried writing a
> regular expression for it. I know that the following selects the
> attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
> @attrB2
> But I cant seem to select the value of this attribute. I get an empty
> string when quering /rootE/tagB/@attrB2/text()


Attributes in the XPath data model don't have any text child nodes.
Simply use
/rootE/tagB/@attrB2
to select the attribute, then you would get the value in a way depending
on the host language e.g. in XSLT with
<xsl:value-of select="/rootE/tagB/@attrB2"/>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      05-19-2008
* (E-Mail Removed) wrote in comp.text.xml:
>Now I want to read the value "attrValueB2" so I tried writing a
>regular expression for it. I know that the following selects the
>attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
>@attrB2
>But I cant seem to select the value of this attribute. I get an empty
>string when quering /rootE/tagB/@attrB2/text()


Use "string(/rootE/tagB/@attrB2)" though string() will be used
implicitly in many cases and is consequently rarely necessary.
--
Björn Höhrmann · (E-Mail Removed) · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 
Reply With Quote
 
pjvleeuwen@gmail.com
Guest
Posts: n/a
 
      05-19-2008
You where both right. Thank you very much. This clarifies a lot.
Cheers,
Paul

On May 19, 1:08 pm, Bjoern Hoehrmann <(E-Mail Removed)> wrote:
> * (E-Mail Removed) wrote in comp.text.xml:
>
> >Now I want to read the value "attrValueB2" so I tried writing a
> >regular expression for it. I know that the following selects the
> >attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
> >@attrB2
> >But I cant seem to select the value of this attribute. I get an empty
> >string when quering /rootE/tagB/@attrB2/text()

>
> Use "string(/rootE/tagB/@attrB2)" though string() will be used
> implicitly in many cases and is consequently rarely necessary.
> --
> Björn Höhrmann · (E-Mail Removed) ·http://bjoern.hoehrmann.de
> Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
> 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath for selecting elements which start with a text node??? Thomas Schmidt XML 7 07-19-2007 11:24 AM
XPath selecting elements afer one having a given text =?ISO-8859-1?Q?Une_B=E9vue?= XML 1 02-22-2007 01:29 PM
picking value of one attribute based on a child elements attribute? XPath? vjethava@gmail.com XML 2 03-06-2006 05:19 AM
selecting content though xpath with text() Mike Kamermans XML 2 10-18-2004 11:02 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments