get attribute values using xquery
Added by Anonymous over 19 years ago
Legacy ID: #3230906 Legacy Poster: anusr (anusr)
I would like to extract the value of the "price" attribute from the following xml file using xquery. My XML file looks like this: ************************************************* <?xml version="1.0" encoding="UTF-8"?> <sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:datagraph="DataGraphRoot.ecore" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:sdo="commonj.sdo"> <models> <ecore:EPackage name="datagraph" nsURI="DataGraphRoot.ecore" nsPrefix="datagraph"> <eClassifiers xsi:type="ecore:EClass" name="sqlj.dummy"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="price" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="DataGraphRoot"> <eStructuralFeatures xsi:type="ecore:EReference" name="sqlj.dummy" upperBound="-1" eType="#//@models.0/sqlj.dummy" containment="true" resolveProxies="false"/> </eClassifiers> </ecore:EPackage> </models> <changeSummary/> <datagraph:DataGraphRoot> <sqlj.dummy price="10"/> <sqlj.dummy price="20"/> <sqlj.dummy price="30"/> </datagraph:DataGraphRoot> </sdo:datagraph> ********************************************** My XQuery looks like: xquery version "1.0"; declare copy-namespaces preserve, inherit; declare namespace sdo ="commonj.sdo"; declare namespace datagraph="DataGraphRoot.ecore"; for $b in doc("file://d:/saxon/pricelist.xml")//sdo:datagraph/datagraph:DataGraphRoot return $b/sqlj.dummy[@price] I want the xquery to return 10, 20, 30..but instead it returns the entire "sqlj.dummy" node from the above xml file. I read in one of postings that we need to use string() or data( ) functions but I don't know how to use it wrt. my query.. Please help.. Thanks in advance, Anu
Replies (1)
RE: get attribute values using xquery - Added by Anonymous over 19 years ago
Legacy ID: #3231223 Legacy Poster: Michael Kay (mhkay)
You should replace $b/sqlj.dummy[@price] with $b/sqlj.dummy/@price For general XQuery coding questions, if they aren't specifically related to Saxon, suggest you try the mailing list at xquery.com Michael Kay
Please register to reply