How to select value from strongly typed XML

Table Name: TableHasXML
has Column: XML_Column xml(XMLCollectionSchema)

XML data is similar to:
[root xmlns="http://thingswelovetohate.com/schema/2010/PinayProgrammer.xsd" ....]
[row ]
[column1]Things We Love to Hate[/column1]
[column2]http://www.thingswelovetohate.com[/column2]
[/row]
[row]
[column1]Pinay Programmer[/column1]
[column2]http://beingoyen.blogspot.com[/column2]
[/row]
....
[/root]

(yes, I know that was sloppy but blogger wouldn't let me just copy-paste my actual schema. Blogger treats any greater than/less than signs as HTML tags)

XML_Column.query('declare default element namespace "http://thingswelovetohate.com/schema/2010/PinayProgrammer.xsd";
data(/root/row[Column1="Things We Love to Hate"]/Column2)')
FROM TableHasXML

Result = http://www.thingswelovetohate.com

If your XML column or variable doesn't have a namespace then leave out the namespace declaration as well:
XML_Column.query('data(/root/row[Column1="Things We Love to Hate"]/Column2)') FROM TableHasXML

No comments: