XQuery
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0596006349
1st edition, , O'Reilly Media, Inc.
Chapter 10: Namespaces and XQuery
<cat:catalog xmlns:cat="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod"> <cat:number>1446</cat:number> <prod:product> <prod:number>563</prod:number> <prod:name prod:language="en">Floppy Sun Hat</prod:name> </prod:product> </cat:catalog>
<foo:catalog xmlns:foo="http://datypic.com/cat" xmlns:bar="http://datypic.com/prod"> <foo:number>1446</foo:number> <bar:product> <bar:number>563</bar:number> <bar:name bar:language="en">Floppy Sun Hat</bar:name> </bar:product> </foo:catalog>
<product xmlns="http://datypic.com/prod" xmlns:app="http://datypic.com/app" app:id="P123" dept="ACC"> ... </product>
<catalog xmlns="http://datypic.com/cat"> <number>1446</number> <prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </catalog>
<catalog xmlns="http://datypic.com/cat"> <number>1446</number> <product xmlns="http://datypic.com/prod"> <number>563</number> <name language="en">Floppy Sun Hat</name> </product> </catalog>
declare namespace rep = "http://datypic.com/report"; declare namespace prod = "http://datypic.com/prod"; <rep:report> { doc("cat_ns.xml")//prod:product } </rep:report>
declare default element namespace "http://datypic.com/cat"; declare namespace rep = "http://datypic.com/report"; declare namespace prod = "http://datypic.com/prod"; <rep:report> { doc("cat_ns.xml")/catalog/prod:product } </rep:report>
declare namespace rep = "http://datypic.com/report"; declare namespace cat = "http://datypic.com/cat"; declare namespace prod2 = "http://datypic.com/prod"; <rep:report> { doc("cat_ns.xml")/cat:catalog/prod2:product } </rep:report>
<rep:report xmlns="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod" xmlns:rep="http://datypic.com/report"> { doc("cat_ns.xml")/catalog/prod:product } </rep:report>
<report xmlns="http://datypic.com/report"> <firstChild/> {doc("prod_ns.xml")/*} </report>
<prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product>
<report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod"> { for $product in doc("prod_ns.xml")/prod:product return <lineItem> {$product/prod:number} {$product/prod:name} </lineItem> } </report>
declare default element namespace "http://datypic.com/report"; declare namespace cat = "http://datypic.com/cat"; declare namespace prod = "http://datypic.com/prod"; <report> { for $product in doc("prod_ns.xml")/prod:product return <lineItem> {$product/prod:number} {$product/prod:name} </lineItem> } </report>
declare namespace cat = "http://datypic.com/cat"; <report xmlns="http://datypic.com/report" xmlns:prod="http://datypic.com/prod"> { for $product in doc("prod_ns.xml")/prod:product return <lineItem> {$product/prod:number} {$product/prod:name} </lineItem> } </report>
<cat:catalog xmlns:cat="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod" xmlns:ord="http://datypic.com/ord"> <prod:product> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </cat:catalog>
declare copy-namespaces no-preserve, inherit; <report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prodnew="http://datypic.com/prod"> { doc("cat_ns2.xml")//prodnew:product } </report>
declare copy-namespaces preserve, no-inherit; <report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prodnew="http://datypic.com/prod"> { doc("cat_ns2.xml")//prodnew:product } </report>