如何在 PL/SQL 过程 ORACLE 中使用 XPATH 读取 XML 中的属性值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5009439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:45:53  来源:igfitidea点击:

How to read the value of attribute in XML using XPATH in a PL/SQL procedure ORACLE?

oraclexsltplsql

提问by Sameer

I have an xml like the following:

我有一个如下所示的 xml:

<!-- XML-Code -->
indoc := '
<Students>
     <Student Enrolled = "true">
           <SID>12456</SID>
    </Student>
    <Student Enrolled = "false">
           <SID>12345</SID>
    </Student>
</Students>';
<!-- XML Code -->
indomdoc := dbms_xmldom.newDomDocument(indoc);

I am using

我在用

dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(indomdoc),
                                        '//Student[@Enrolled="True"]');

This is returning me the values Of Students with attribute Enrolled as true.

这将返回属性为 true 的学生的值。

and again I am using

我再次使用

dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(indomdoc),
                                        '//Student[@Enrolled="False"]');

to get all students who are not enrolled yet.

获取所有尚未注册的学生。

But I want to know is there any way to find the value of enrolled attribute using xsl processor, rather than directly giving like @Enrolled="True"and @Enrolled="False".

但我想知道有没有什么办法可以使用 xsl 处理器找到注册属性的值,而不是直接给出 like@Enrolled="True"@Enrolled="False"

回答by Alex Nikolaenkov

XPath expression //Student/@Enrolledwill give you all the values of the Enrolledattribute.

XPath 表达式//Student/@Enrolled将为您提供该Enrolled属性的所有值。

回答by collapsar

How about using an XPath expression referencing the attribute value?

如何使用引用属性值的 XPath 表达式?

fn:data(//Student/@Enrolled)

Am I missing some part of your problem?

我错过了你的问题的一部分吗?