从xml文件获取属性
我的XML文件条目:从xml文件获取属性,xml,namespaces,xquery,Xml,Namespaces,Xquery,我的XML文件条目: <GlobalView xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <rels> <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Targ
<GlobalView xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<rels>
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
</rels>
提前感谢试试看
GlobalView/child::rels/child::Relationship/@Id
或者用缩写的形式
GlobalView/rels/Relationship/@Id
使用:
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
提供的原始代码存在两个明显的问题:
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
$file
中的XML文档具有默认命名空间。如果没有声明,则表达式中所有未固定的名称都将被视为属于“无命名空间”,并且不会选择任何节点关系
元素,但该元素的属性Id
才是真正需要的声明默认元素命名空间“”;对于文档中的$file(“C:/Users/Raffay/Desktop/RnDxr.xml”)返回$file/GlobalView/rels/Relationship/@Id,此代码给出以下错误:“XQuery序列化错误!文档节点可能没有属性节点或命名空间节点作为子节点”…:(@user399493:是的,假设您将这些属性分配给一个变量。我编辑了我的答案,代码现在显式地这样做了。给定以下错误:XQuery执行错误!意外的语句结尾没有ur AMMENDENT,它会给出一个错误:[DataDirect][XQuery][err SENR0001]以下给定查询不支持顶级属性节点。查询:文档中的$file(“C:/Users/Raffay/Desktop/RnDxr.xml”)返回$file/GlobalView/rels/Relationship/@Id@user399493:在我的解决方案中,我正在收集变量中所有属性的序列。此后如何使用此变量取决于您,但您已经得到了问题的答案。声明默认元素名称空间“”;用于文档中的$file(“C:/Users/Raffay/Desktop/RnDxr.xml”)return$file/GlobalView/rels/Relationship/@Id此代码给出以下错误:“XQuery序列化错误!文档节点可能没有属性节点或命名空间节点作为子节点”。…:(-