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

How to know if a string is part of an XML?

I have a table named "TempTable" with an XML column named "XML_Collection". Now I want to know if the string "My Valentine" appears in any of those XML rows.

I used the string manipulator: PATINDEX

SELECT * from TempTable WHERE PATINDEX('%My Valentine%', convert(varchar(max),XML_Collection)) > 0

Important notes:
  • be sure to convert the XML type to varchar(max) first before using any string manipulator functions
  • if PatIndex == 0 then that string pattern does not exist
  • if PatIndex > 0 then that string pattern exists