<root>
<id>1</id>
<text>控制面板</text>
<isleaf>1</isleaf>
<sort>1</sort>
<link>www.xxxxx.com</link>
<target>_bank</target>
<children>
<node>
<id>11</id>
<text>默认控制</text>
<isleaf>0</isleaf>
<sort>1</sort>
<link>www.xxxxx.com</link>
<target>_bank</target>
</node>
<node>
<id>12</id>
<text>享受控制</text>
<isleaf>0</isleaf>
<sort>1</sort>
<link>www.xxxxx.com</link>
<target>_bank</target>
</node>
</children>
</root>
我有这样一个xml ...现在我想删除下面整个节点。另外如果要将下面整个节点更新为另一个节点。。该如何写
                        <node><id>11</id>
<text>默认控制</text>
<isleaf>0</isleaf>
<sort>1</sort>
<link>www.xxxxx.com</link>
<target>_bank</target>
</node>
我的写法:(报错) 
 UPDATE t  set tree = updateXML(tree,'/root/node[extractValue('/root/node/id=11')]','<node><id>1</id><name>是的</name><link>www.xx</link></node>')
 update t set tree=deletexml(tree,'/root/nodenode[extractValue('/root/node/id=11')') where id=4;

解决方案 »

  1.   


    --删除
    update t set tree=deletexml(tree,'/root/children/node[id=11]') where id=4;--更新
    update t 
    set tree=
    updatexml(tree,
    '/root/children/node[id=11]',
    '<node><id>1</id><name>是的</name><link>www.xx</link></node>') ;
      

  2.   

    xmlpath用法
    Table 4-1 Common XPath ConstructsXPath Construct Description 
    /
     Denotes the root of the tree in an XPath expression. For example, /PO refers to the child of the root node whose name is PO.
     
    /
     Also used as a path separator to identify the children node of any given node. For example, /PurchaseOrder/Reference identifies the purchase-order name element Reference, a child of the root element.
     
    //
     Used to identify all descendants of the current node. For example, PurchaseOrder//ShippingInstructions matches any ShippingInstructions element under the PurchaseOrder element.
     
    *
     Used as a wildcard to match any child node. For example, /PO/*/STREET matches any street element that is a grandchild of the PO element.
     
    [ ]
     Used to denote predicate expressions. XPath supports a rich list of binary operators such as OR, AND, and NOT. For example, /PO[PONO=20 AND PNAME="PO_2"]/SHIPADDR selects the shipping address element of all purchase orders whose purchase-order number is 20 and whose purchase-order name is PO_2.Brackets are also used to denote an index into a list. For example, /PO/PONO[2] identifies the second purchase-order number element under the PO root element.
     
    Functions
     XPath supports a set of built-in functions such as substring(), round(), and not(). In addition, XPath allows extension functions through the use of namespaces. In the Oracle namespace, http://xmlns.oracle.com/xdb, Oracle XML DB additionally supports the function ora:contains(). This functions behaves like the equivalent SQL function.
     SQL> select id,t.name.getstringval() from t_xml_update t where id=1;
     
             ID T.NAME.GETSTRINGVAL()
    ----------- --------------------------------------------------------------------------------
              1 <root>
                  <node>
                    <id>1</id>
                    <name>不是的</name>
                    <link>www.xyyx</link>
                  </node>
                  <node>
                    <id>2</id>
                    <name>3</name>
                    <link>4</link>
                  </node>
                </root>
     
    SQL> 
    SQL> UPDATE t_xml_update
      2    set name = updateXML(name,'/root/node[id=1]','<node><id>1</id><name>no</name><link>www</link></node>')
      3  where id=1;
     
    1 row updated
     
    SQL> select id,t.name.getstringval() from t_xml_update t where id=1;
     
             ID T.NAME.GETSTRINGVAL()
    ----------- --------------------------------------------------------------------------------
              1 <root>
                  <node>
                    <id>1</id>
                    <name>no</name>
                    <link>www</link>
                  </node>
                  <node>
                    <id>2</id>
                    <name>3</name>
                    <link>4</link>
                  </node>
                </root>
     
    SQL> 
      

  3.   

    翻译一下.
    /表示根节点,同时它也是路径分隔符./PurchaseOrder/Reference,前一个/代表根节点,后一个/即路径分隔符.
    //用来匹配当前节点的所有子节点.
    *用来匹配当前节点的任意子节点./PO/*/STREET匹配PO下任何子节点,*和//的趋避,*是当前节点的所有子节点(1层),//是所有后代,是以当前节点为根的一棵新树.
    []用来指定谓词,也就是说类似where后面的条件.这里支持逻辑判断 and or not.例如/PO[PONO=20 AND PNAME="PO_2"]/SHIPADDR.
      另外[]还类似c中的数组下标引用,/PO/PONO[2]
    function
    xmlpath支持内建函数,例如substring(), round(), and not();