xml - Getting an element that has specific attribute -


my xml looks this

<data>   <a messages="1">   <b messages="2" labelvisibility="yes">   <c messages="3"> </data> 

i want select element has attribute named labelvisibility. there 1 such element @ time.

my attempt was: (assuming "a" xml file above)

var b = a.selectsinglenode("//messages[@labelvisibility]"); 

according w3schools, expression: //title[@lang] selects title elements have attribute named lang

so trying element has attribute name labelvisibility following example, code returns null. doing wrong? if there esier/smarter way 1 w3schools, please share.

thanks

-------------------------------update-------------------------------------.....

i see wasn't clear , precise in question. want return is: `messages="another"

in case want return attribute value`. if this:

a.selectsinglemode("//@messages") 

it print messages="1"

how can print attribute value of "message" there labelvisibility attribute?

so print 2 (since value 2 there labelvisibility)

you don't have messages element in xml, that's why result null.

fixed version:

var b = a.selectsinglenode("//*[@messages][@labelvisibility]"); 

i.e. elements contain both messages , labelvisibility attributes. if check messages attribute surplus, can remove predicate.


a.selectsinglemode("//@messages") print messages="1"

this happens because //@messages returns 3 attribute nodes , 1 first 1 according document order.

how can print attribute value of "message" there labelvisibility attribute?

so print 2 (since value 2 there labelvisibility)

var b = a.selectsinglenode("//*[@labelvisibility]/@messages"); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -