从xml文件获取属性

发布于 2024-09-12 04:52:35 字数 552 浏览 0 评论 0原文

我的 XML 文件条目:

<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>

想要查询关系元素内的属性 Id... 我正在使用下面给出的查询,它一直有效直到元素关系并且没有给我 Id 属性的值。

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

提前致谢

My XML file entry:

<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>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅倚清风 2024-09-19 04:52:35

尝试

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

或以缩写形式

GlobalView/rels/Relationship/@Id

Try

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

or in abbreviated form

GlobalView/rels/Relationship/@Id
没企图 2024-09-19 04:52:35

使用

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

提供的原始代码有两个明显的问题

  1. $file中包含的XML文档有一个默认值命名空间。没有声明默认元素命名空间 表达式中所有无前缀的名称都被视为属于“无命名空间”,并且不会选择任何节点。

  2. 该表达式旨在选择一个Relationship元素,但该元素的属性Id才是真正想要的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文