Difference between text() and string()

Can someone explain the difference between text() and string() functions. I. text() isn’t a function but a node test. It is used to select all text-node children of the context node. So, if the context node is an element named x, then text() selects all text-node children of x. Other examples: /a/b/c/text() selects all text-node … Read more

Nokogiri/Xpath namespace query

All namespaces need to be registered when parsing. Nokogiri automatically registers namespaces on the root node. Any namespaces that are not on the root node you have to register yourself. This should work: puts doc.xpath(‘//dc:title’, ‘dc’ => “URI”) Alternately, you can remove namespaces altogether. Only do this if you are certain there will be no … Read more

XPath 1.0 to find if an element’s value is in a list of values

You can check multiple conditions inside the same square brackets: /Location/Addr[State=”TX” or State=”AL” or State=”MA”] Or if you have a really long list, you can create a list of states and use the contains() function. /Location/Addr[contains(‘TX AL MA’, State)] This will work fine for two-letter state abbreviations. If you want to make it more robust … Read more

Apostrophe (‘) in XPath query

This is surprisingly difficult to do. Take a look at the XPath Recommendation, and you’ll see that it defines a literal as: Literal ::= ‘”‘ [^”]* ‘”‘ | “‘” [^’]* “‘” Which is to say, string literals in XPath expressions can contain apostrophes or double quotes but not both. You can’t use escaping to get … Read more

Why is CROSS APPLY needed when using XPath queries?

Query: SELECT x.i.value(‘(./text())[1]’, ‘VARCHAR(10)’) FROM MyTable.SomeXmlColumn.nodes(‘./people/person/firstName’) AS x(i); doesn’t work, for the same reason why this query doesn’t work: SELECT * FROM Person.Person.FirstName; but this does: SELECT FirstName FROM Person.Person; – FROM clause expects rowset, so this is valid, since nodes() returns rowset: DECLARE @xml AS XML = ‘<people> <person><firstName>Jon</firstName><lastName>Johnson</lastName></person> <person><firstName>Kathy</firstName><lastName>Carter</lastName></person> <person><firstName>Bob</firstName><lastName>Burns</lastName></person> </people>’; SELECT x.i.value(‘(./text())[1]’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)