如何使用 Oracle XMLTABLE XML XML 中的列
How to return a column from XML using Oracle XMLTABLE
我有一些 XML
存储在 table 中。我需要能够接受这个 XML
并提取某些值。
我已经编写了一些代码来尝试 return <ns1:Int32/>
标记的值,但到目前为止我还没有能够 return 结果。
我在网上找到了几个使用 XMLTABLE
函数的示例,但不幸的是,其中很多示例使用的 XML
比我的更简单。
XML
<Rule Priority="0" Description="Description 1" Active="True" ReevaluationBehavior="Always" Name="Name 1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<Rule.Condition>
<RuleExpressionCondition Name="{p3:Null}" xmlns:p3="http://schemas.microsoft.com/winfx/2006/xaml">
<RuleExpressionCondition.Expression>
<ns0:CodeBinaryOperatorExpression Operator="BooleanAnd" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<ns0:CodeBinaryOperatorExpression.Right>
<ns0:CodeBinaryOperatorExpression Operator="GreaterThanOrEqual">
<ns0:CodeBinaryOperatorExpression.Right>
<ns0:CodePrimitiveExpression>
<ns0:CodePrimitiveExpression.Value>
<ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">11</ns1:Int32>
</ns0:CodePrimitiveExpression.Value>
</ns0:CodePrimitiveExpression>
</ns0:CodeBinaryOperatorExpression.Right>
</ns0:CodeBinaryOperatorExpression>
</ns0:CodeBinaryOperatorExpression.Right>
</ns0:CodeBinaryOperatorExpression>
</RuleExpressionCondition.Expression>
</RuleExpressionCondition>
</Rule.Condition>
</Rule>
SQL
SELECT Rules2.*
FROM RULES Rules1,
XMLTABLE
(
XMLNAMESPACES
(
'http://schemas.microsoft.com/winfx/2006/xaml' AS "p3",
'clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns0",
'clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns1",
DEFAULT 'http://schemas.microsoft.com/winfx/2006/xaml/workflow'
)
,
'/Rule/RuleExpressionCondition/CodeBinaryOperatorExpression/CodePrimitiveExpression'
PASSING XMLPARSE(CONTENT Rules1.RULE WELLFORMED)
COLUMNS "Int" INT PATH 'ns1:Int32'
)
Rules2
;
非常感谢任何帮助。
ns0 的命名空间定义中有错误 url。 xmltable 中的路径错误。您可以使用简短版本。或者提供完整路径。
/Rule/Rule.Condition/RuleExpressionCondition/RuleExpressionCondition.Expression/ns0:CodeBinaryOperatorExpression/ns0:CodeBinaryOperatorExpression.Right/ns0:CodeBinaryOperatorExpression/ns0:CodeBinaryOperatorExpression.Right/ns0:CodePrimitiveExpression/ns0:CodePrimitiveExpression.Value
SELECT Rules2.*
FROM xmls Rules1,
XMLTABLE
(
XMLNAMESPACES
(
'http://schemas.microsoft.com/winfx/2006/xaml' AS "p3",
'clr-namespace:System.CodeDom;Assembly=System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns0",
'clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns1",
DEFAULT 'http://schemas.microsoft.com/winfx/2006/xaml/workflow'
)
,
'//ns0:CodePrimitiveExpression.Value'
PASSING XMLPARSE(CONTENT Rules1.RULE WELLFORMED)
COLUMNS "Int" INT PATH 'ns1:Int32'
)
Rules2
我认为问题是你的搜索表达式是
/Rule/RuleExpressionCondition/CodeBinaryOperatorExpression/CodePrimitiveExpression
.
表达式缺少多个节点,对吗?
我有一些 XML
存储在 table 中。我需要能够接受这个 XML
并提取某些值。
我已经编写了一些代码来尝试 return <ns1:Int32/>
标记的值,但到目前为止我还没有能够 return 结果。
我在网上找到了几个使用 XMLTABLE
函数的示例,但不幸的是,其中很多示例使用的 XML
比我的更简单。
XML
<Rule Priority="0" Description="Description 1" Active="True" ReevaluationBehavior="Always" Name="Name 1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<Rule.Condition>
<RuleExpressionCondition Name="{p3:Null}" xmlns:p3="http://schemas.microsoft.com/winfx/2006/xaml">
<RuleExpressionCondition.Expression>
<ns0:CodeBinaryOperatorExpression Operator="BooleanAnd" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<ns0:CodeBinaryOperatorExpression.Right>
<ns0:CodeBinaryOperatorExpression Operator="GreaterThanOrEqual">
<ns0:CodeBinaryOperatorExpression.Right>
<ns0:CodePrimitiveExpression>
<ns0:CodePrimitiveExpression.Value>
<ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">11</ns1:Int32>
</ns0:CodePrimitiveExpression.Value>
</ns0:CodePrimitiveExpression>
</ns0:CodeBinaryOperatorExpression.Right>
</ns0:CodeBinaryOperatorExpression>
</ns0:CodeBinaryOperatorExpression.Right>
</ns0:CodeBinaryOperatorExpression>
</RuleExpressionCondition.Expression>
</RuleExpressionCondition>
</Rule.Condition>
</Rule>
SQL
SELECT Rules2.*
FROM RULES Rules1,
XMLTABLE
(
XMLNAMESPACES
(
'http://schemas.microsoft.com/winfx/2006/xaml' AS "p3",
'clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns0",
'clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns1",
DEFAULT 'http://schemas.microsoft.com/winfx/2006/xaml/workflow'
)
,
'/Rule/RuleExpressionCondition/CodeBinaryOperatorExpression/CodePrimitiveExpression'
PASSING XMLPARSE(CONTENT Rules1.RULE WELLFORMED)
COLUMNS "Int" INT PATH 'ns1:Int32'
)
Rules2
;
非常感谢任何帮助。
ns0 的命名空间定义中有错误 url。 xmltable 中的路径错误。您可以使用简短版本。或者提供完整路径。
/Rule/Rule.Condition/RuleExpressionCondition/RuleExpressionCondition.Expression/ns0:CodeBinaryOperatorExpression/ns0:CodeBinaryOperatorExpression.Right/ns0:CodeBinaryOperatorExpression/ns0:CodeBinaryOperatorExpression.Right/ns0:CodePrimitiveExpression/ns0:CodePrimitiveExpression.Value
SELECT Rules2.*
FROM xmls Rules1,
XMLTABLE
(
XMLNAMESPACES
(
'http://schemas.microsoft.com/winfx/2006/xaml' AS "p3",
'clr-namespace:System.CodeDom;Assembly=System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns0",
'clr-namespace:System;Assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' AS "ns1",
DEFAULT 'http://schemas.microsoft.com/winfx/2006/xaml/workflow'
)
,
'//ns0:CodePrimitiveExpression.Value'
PASSING XMLPARSE(CONTENT Rules1.RULE WELLFORMED)
COLUMNS "Int" INT PATH 'ns1:Int32'
)
Rules2
我认为问题是你的搜索表达式是
/Rule/RuleExpressionCondition/CodeBinaryOperatorExpression/CodePrimitiveExpression
.
表达式缺少多个节点,对吗?