[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Fwd: querying attribute?

Thomas R. Jones thomas.jones at maitreyasecurity.com
Wed Mar 18 17:06:24 PST 2009


 Fwd:  querying attribute?
The following message was mistakingly only sent to ken. I'm forwarding  
it to the list at his request so that other users may benefit from his  
insight. :)

Thomas

Sent from my iPhone

Begin forwarded message:

> From: "Thomas R. Jones" <http://x-query.com/mailman/listinfo/talk>
> Date: March 18, 2009 2:42:49 PM CDT
> To: "G. Ken Holman" <http://x-query.com/mailman/listinfo/talk>
> Subject: Re:  querying attribute?
>

> Thanks so much for your response ken.
>
> So it is correct to declare and reference namespace prefixes within  
> xquery even though they are not "explicitly" done so in source code?  
> I'm guessing the parser is handling this natively. The XML source is  
> located within an international database and it strips prefix  
> declarations within the import triggers. :(
>
> I'll try this as soon as I get home. Thanks again
>
> Sent from my iPhone
>
> On Mar 18, 2009, at 2:05 PM, "G. Ken Holman" <http://x-query.com/mailman/listinfo/talk 
> > wrote:
>
>> At 2009-03-18 13:06 -0400, Thomas R. Jones wrote:
>>> Hello all, I have the following code:
>>>
>>> <tests xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5">
>>> <rpminfo_test
>>> xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
>>> check="all" comment="apache2 is installed"
>>> id="oval:com.maitreyasecurity:tst:674" version="1">
>>> <object object_ref="oval:com.maitreyasecurity:obj:674"/>
>>> <state state_ref="oval:com.maitreyasecurity:ste:500"/>
>>> </rpminfo_test>
>>> </tests>
>>>
>>> I am trying everything i can think of to return the attribute  
>>> value but
>>> am hanging up on the namespace(i think). I believe because the  
>>> attribute
>>> is not prefixed that it is located within a NULL namespace and not  
>>> the
>>> element default namespace declared----correct?
>>
>> Yes, that is correct. *All* unprefixed attributes are in no  
>> namespace, never the default namespace.
>>
>>
>>> Here is my xquery:
>>>
>>> declare default element namespace
>>> "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"; for  
>>> $attr in
>>> document( 
>>> "apache2.package.novell.maitreyasecurity.en_US.xml","inventory.a")/ 
>>> tests/rpminfo_test/@id return string($attr)
>>>
>>> Ideas?
>>
>> You declare the "#linux" namespace as your default element  
>> namespace, so it is being applied to *every* element (after all, it  
>> is the default) which includes the <tests> element.  Your <tests>  
>> element is in not in the "#linux" namespace, so your problem is it  
>> isn't finding the element with the attribute, not that it isn't  
>> finding the attribute.
>>
>> I tell my students that using the default namespace can be awkward  
>> when dealing with an instance of numerous namespaces (as I learned  
>> the hard way when working with UBL).  I believe it will make  
>> maintenance easier if you explicitly use prefixes when there is  
>> more than one namespace in your source tree.
>>
>> A running example is below ... I hope this helps.
>>
>> . . . . . . . . . Ken
>>
>> t:\ftemp>type thomas.xml
>> <tests xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5">
>> <rpminfo_test
>> xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
>> check="all" comment="apache2 is installed"
>> id="oval:com.maitreyasecurity:tst:674" version="1">
>> <object object_ref="oval:com.maitreyasecurity:obj:674"/>
>> <state state_ref="oval:com.maitreyasecurity:ste:500"/>
>> </rpminfo_test>
>> </tests>
>>
>> t:\ftemp>call xquery thomas.xml thomas.xq
>> <?xml version="1.0" encoding="UTF-8"?>oval:com.maitreyasecurity:tst: 
>> 674
>> t:\ftemp>type thomas.xq
>> declare namespace o =
>>       "http://oval.mitre.org/XMLSchema/oval-definitions-5";
>> declare namespace l =
>>       "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";
>> for $attr in
>> /o:tests/l:rpminfo_test/@id return string($attr)
>>
>> t:\ftemp>
>>
>>
>> --
>> XQuery/XSLT/XSL-FO training in Los Angeles (New dates!) 2009-06-08
>> Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
>> Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
>> Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
>> G. Ken Holman                 mailto:http://x-query.com/mailman/listinfo/talk
>> Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
>> Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
>> Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
>>
>> _______________________________________________
>> http://x-query.com/mailman/listinfo/talk
>> http://x-query.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090318/36494859/attachment.htm


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.