Querying with namespaces : namespace « XQuery « XML






Querying with namespaces


File: Data.xml

<prod:car xmlns:prod="http://java2s.com/prod">
  <prod:id>0002</prod:id>
  <prod:name language="en">name 2</prod:name>
</prod:car>


File: Query.xquery

declare namespace prod = "http://java2s.com/prod";
for $car in doc("Data.xml")/prod:car
return $car/prod:name

Output:

<?xml version="1.0" encoding="UTF-8"?>
<prod:name xmlns:prod="http://java2s.com/prod" language="en">name 2</prod:name>

 








Related examples in the same category

1.Prefixed name tests
2.Using a namespace declaration in a constructor
3.Namespace declarations in query different from input document
4.Using namespace declaration attributes
5.Namespace declaration impact on input elements
6.Using XML namespace declarations
7.Prolog namespace declarations