Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Xpath query to return "NULL" values?

From: Mario Splivalo <majk@---.---.---.-->
To: NULL
Date: 6/6/2009 10:30:00 AM
On 2009-06-06, Martin Honnen <mahotrash@y...> wrote:
> Mario Splivalo wrote:
>
>> <itemList>
>>   <item fieldName="name">Mario</item>
>>   <item fieldName="age">29</item>
>>   <item fieldName="height"></item>
>> </itemList>
>> 
>> What I'm trying to get is a rowset or table, since I'm doing this from
>> postgres. So, my table would look like this:
>> 
>> fieldName      fieldValue
>> name           Mario
>> age            29
>> height         NULL
>> 
>> The idea was to have two XPath queries on the original XML. First one
>> ('/itemList/item/@fieldName') would extract all the attributes, and second
>> one would extract all the 'values' ('/itemList/item/text()'). Now I guess
>> I'll have to extract the nodes, as you've suggested, and then for each node
>> chech if it's empty or not.
>
> Are you using XPath inside of XSLT? There is no need to use foo/text() 
> to get the string value of a 'foo' element, an element does have a 
> string value of its own for instance with XSLT
>    <xsl:value-of select="foo"/>
> would suffice. If you are using an XPath API then check how it allows 
> you to extract the string value of a node.

Nope, I'm using it inside postgresql. Postgresql has rudimentary XML support
(http://www.postgresql.org/docs/8.3/interactive/functions-xml.html#FUNCTIONS-XML-PROCESSING)
there is a XPath function which returns onedimensional array of type xml[]
(xml type, in postgres, is varchar/text with added support for xml
validation). Function accept xpath query and xml document, I'm clueless how
to extract string value of a node. It's based on libxml2, so it should be
able to do so, but, I guess i'm stuck:

postgres=# select xpath('/a/b', '<a><b>1</b><b></b></a>');
      xpath      
-----------------
 {<b>1</b>,<b/>}
(1 row)

So, I have an array where each element is XML document. I could run an xpath
query ('/b') on each of those elements and like that find out which ones are
empty.

	Mike
-- 
"I can do it quick. I can do it cheap. I can do it well. Pick any two."

Mario Splivalo
majk@f...


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent