468,119 Members | 2,060 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

filtering nodes containiing qname valuies using xpath

hi, while playing with the SAML specs I found that one must insert a node like this if the call succeded

<status xmlns:z=mynamspace" ...

<z:statuscode result="z:Sucess"/>

...

How do I set up an XPATH filter that veriffies if the call succeed ? .. I mean i cannot hardcode z:Success since another one could pass me out a doc like this

<x xmlns:k=mynamspace" ...

<k:statuscode result="k:Sucess"/>

...

The code I wrote is something like what you see below .. however I wonder if there is a way to make xpath aware of namepsace while evaluating elements and attributes text ..

I mean, what an XSd parser does when meets type="xsd:string" ?

string s = "<a xmlns:k='abcd' ><b k:aa='k:success'></b></a>";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument ();
doc.LoadXml (s);
XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable );
ns.AddNamespace ("xx","abcd");
string dd = "//@xx:aa[.='" + doc.DocumentElement.GetPrefixOfNamespace("abcd") + ":success']";
XmlNode x = doc.SelectSingleNode (dd,ns);
System.Diagnostics.Debug.WriteLine ( x.InnerText );

suggestions are welcome
--
Enrico Sabbadin
Mail: sa******@sabbasoft.com
Website: http://www.sabbasoft.com
********
MTS - COM+ - VBCOM - Enterprise Services - Security FAQ
..NET & COM+ books selected list
********
Blog: http://www.sabbasoft.com/myblog

Affiliated Sites
http://www.vb2themax.com
http://www.codearchitects.com
Nov 12 '05 #1
1 1412
enrico sabbadin @ infinito wrote:
hi, while playing with the SAML specs I found that one must insert a
node like this if the call succeded

<status xmlns:z=mynamspace" ...

<z:statuscode result="z:Sucess"/>

How do I set up an XPATH filter that veriffies if the call succeed ? ..
I mean i cannot hardcode z:Success since another one could pass me out a
doc like this

<x xmlns:k=mynamspace" ...

<k:statuscode result="k:Sucess"/>

The code I wrote is something like what you see below .. however I
wonder if there is a way to make xpath aware of namepsace while
evaluating elements and attributes text ..


Yeah, but not in a strughtforward way. Something like:

//@result[
substring-after(., ':')='Sucess' and
name(../namespace::*[.='mynamspace'])=substring-before(., ':')
]

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by serge calderara | last post: by
2 posts views Thread by Felicity | last post: by
5 posts views Thread by David Thielen | last post: by
6 posts views Thread by Paul J Lay | last post: by
1 post views Thread by Christian Rühl | last post: by
1 post views Thread by Christian Rühl | last post: by
1 post views Thread by Arndt Jonasson | last post: by
14 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.