views:

49

answers:

2

My XML file entry:

<GlobalView xmlns="http://schemas.openxmlformats.org/package/2006/relationships"&gt;
    <rels>
        <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
    </rels>

wanna query attribute Id inside Relationship element.... I am using the query given below and it works till element Relationship and not giving me the value of Id attribute.

for $file in doc("C:/Users/Raffay/Desktop/RnDxr.xml")
return $file/GlobalView/child::rels/child::Relationship

Thanking in advance

A: 

Try

GlobalView/child::rels/child::Relationship/@Id

or in abbreviated form

GlobalView/rels/Relationship/@Id
Jim Garrison
declare default element namespace "http://schemas.openxmlformats.org/package/2006/relationships"; for $file in doc("C:/Users/Raffay/Desktop/RnDxr.xml") return $file/GlobalView/rels/Relationship/@Id this code gives me following error: "XQuery Serialization Error! A document node may not have an attribute node or a namespace node as a child".... :( –
A: 

Use:

declare default element namespace 
     "http://schemas.openxmlformats.org/package/2006/relationships";

let $vIds := 
    for $file in doc("C:/Users/Raffay/Desktop/RnDxr.xml") 
     return $file/GlobalView/rels/Relationship/@Id

There are two visible problems with the provided original code:

  1. The XML document contained in $file has a default namespace. Without a declaration of default element namespace all unprefixed names in an expression are considered to belong in "no namespace" and no node would be selected.

  2. The expression aims to select a Relationship element, but the attribute Id of this element is what is really is wanted.

Dimitre Novatchev
declare default element namespace "http://schemas.openxmlformats.org/package/2006/relationships";for $file in doc("C:/Users/Raffay/Desktop/RnDxr.xml") return $file/GlobalView/rels/Relationship/@Idthis code gives me following error: "XQuery Serialization Error!A document node may not have an attribute node or a namespace node as a child"....:(
@user399493: Yes, It was supposed that you'll assign these attributes to a variable. I edited my answer and the code now explicitly does so.
Dimitre Novatchev
Given following error: XQuery Execution Error!Unexpected end of statement
without ur ammendment it gives an error that :[DataDirect][XQuery][err:SENR0001]Top-level attribute nodes are not supported for below given query.Query: for $file in doc("C:/Users/Raffay/Desktop/RnDxr.xml") return $file/GlobalView/rels/Relationship/@Id
@user399493: In my solution I am collecting the sequence all attributes in a variable. How to use this variable thereafter is up to you, but you've got an answer to your question.
Dimitre Novatchev
No, I want the values of the attributes so I can handle them according to my condition and so far its not giving me the values.... raising an error if try to access "Id" attribute.... TOP LEVEL NODES R NOT SUPPORTED... any help is highly aprciated