我有以下结构的 xml。只想从以下内容中提取名称信息。我正在为此使用提取功能。但是为了仅提取“名称”,我的 xml 路径应该是什么?我尝试了所有方法。请帮助如何填写此查询。
<Employee>
<Basics>
<Attribute Name="Scope">LOCAL</Attribute>
<Attribute Name="Name">Narendra</Attribute>
<Attribute Name="Id">12345</Attribute>
<Attribute Name="Type">EMPLOYEE</Attribute>
<Attribute Name="Revision"/>
</Basics>
</Employee>
我的查询如下。
SELECT
extract(value(N), 'Attribute/text()').getStringVal() AS Emp_Name
FROM Employee A,
table(xmlsequence(extract(A.XML_INFO, '/Employee/Basics/Attribute'))) N
最佳答案
在 xpath 中,您使用谓词 ([]
) 来根据某些特定条件过滤元素。例如,您可以使用以下 xpath 获取 <Attribute>
具有 Name
的元素属性值等于 "Name"
:
/Employee/Basics/Attribute[@Name="Name"]
关于xml - 根据属性名称提取 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30526336/