从XML获取Name标记

时间:2015-01-10 09:27:47

标签: sql xpath

<Attribute DisplayOrder="-1">
    <Categories>
<Category Name="Properties">
<Properties>
<Property Name="Visible" Value="True"/>
<Property Name="Enabled" Value="False"/>
<Property Name="Mandatory" Value="True"/>
<Property Name="Button" Value="True"/>
<Property Name="Label">
                    <Locales>
                        <Locale Name="en" Value="Device Selection Button"/>
                    </Locales>
                </Property>
<Property Name="Style" Value=""/>
<Property Name="ShowHelpText" Value="False"/>
<Property Name="EventChange" Value="False"/>
<Property Name="Mask" Value=""/>
<Property Name="NumberOfLines" Value="1"/>
<Property Name="EditType" Value="0"/>
<Property Name="ButtonCaption">
                    <Locales>
                        <Locale Name="en" Value="Select Device"/>
                    </Locales>
                </Property>
</Properties>
</Category>
<Category Name="External Functions">
<Properties>
<Property Name="function" Value="SelectEquipmentByCategory"/>
<Property Name="actionType" Value="SetOne"/>
<Property Name="Parameters" Value="Devices_Cat,4355608"/>
</Properties>
</Category>
</Categories>
</Attribute>

我有这个XML,在SQL中我想要选择设备的值。

查询:

SELECT EXTRACTVALUE(xmltype(display_info_xml), '/Attribute/Categories/Properties/Property[@Name="Label"]/Locales/Locale[@Name="en"]/Value') 
FROM table

现在Query返回空白。 我试图创建所有XPATH但没有用。 请帮助。

编辑:

更新了查询:

/属性/分类/类别[@名称= “属性”] /属性/属性[@名称= “标签”] /区域设置/语言代码[@名称= “EN”] /值

仍然失败,没有数据作为回报。

2 个答案:

答案 0 :(得分:1)

您缺少Category标记。

此外,Value属性应添加@。 (http://www.tizag.com/xmlTutorial/xpathattribute.php

正确的XPATH是/Attribute/Categories/Category/Properties/Property[@Name="Label"]/Locales/Locale[@Name="en"]/@Value

答案 1 :(得分:0)

我认为你应该像这样试试

SELECT EXTRACTVALUE(xmltype(display_info_xml), '//Property[@Name="ButtonCaption"]/Locales/Locale[@Name="en"]/Value') 
FROM table

OR

SELECT EXTRACTVALUE(xmltype(display_info_xml), '/Attribute/Categories/Category/Properties/Property[@Name="ButtonCaption"]/Locales/Locale[@Name="en"]/Value') 
FROM table

你写的是你想要在你的例子中选择设备的值,你将值指定为设备选择按钮