Extract XML based on attribute name
I have xml with the following structure. Want to extract only title information from the following. For this I use the extract function. But in order to extract only "Name" what should my xml path be? I've tried everything. Please help fill out the request for this.
<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>
My request looks like this.
SELECT
extract(value(N), 'Attribute/text()').getStringVal() AS Emp_Name
FROM Employee A,
table(xmlsequence(extract(A.XML_INFO, '/Employee/Basics/Attribute'))) N
+3
narendra gc
source
to share
1 answer
In xpath, you use a predicate ( []
) to filter an element with certain criteria. For example, you can use the following xpath to get an element <Attribute>
that has an attribute value Name
equal to "Name"
:
/Employee/Basics/Attribute[@Name="Name"]
0
har07
source
to share