在xmlDB中的XML中插入新标记

时间:2016-03-07 10:11:26

标签: oracle-xml-db oracle-xml-db-repository

是否可以在XML数据库中的XML中插入新标记?

例如;下面是我在数据库中存在的例子:

<PurchaseOrder 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
    "http://localhost:8080/source/schemas/poSource/xsd/purchaseOrder.xsd">
  <Reference>SBELL-2002100912333601PDT</Reference>
  <Actions>
    <Action>
      <User>SVOLLMAN</User>
    </Action>
  </Actions>
  <Reject/>
  <Requestor>Sarah J. Bell</Requestor>
  <User>SBELL</User>
  <CostCenter>S30</CostCenter>
  <SpecialInstructions>Air Mail</SpecialInstructions>
  <LineItems>
    <LineItem ItemNumber="1">
      <Description>A Night to Remember</Description>
      <Part Id="715515009058" UnitPrice="39.95" Quantity="2"/>
    </LineItem>
  </LineItems>
</PurchaseOrder>

我需要在<sender>xxxx</sender>为'S30'的位置插入新标记<costCente>

插入/更新XML后,它应如下所示:

<PurchaseOrder 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
    "http://localhost:8080/source/schemas/poSource/xsd/purchaseOrder.xsd">
  <Reference>SBELL-2002100912333601PDT</Reference>
  <sender>xxx</sender>
  <Actions>
    <Action>
      <User>SVOLLMAN</User>
    </Action>
  </Actions>
  <Reject/>
  <Requestor>Sarah J. Bell</Requestor>
  <User>SBELL</User>
  <CostCenter>S30</CostCenter>
  <SpecialInstructions>Air Mail</SpecialInstructions>
  <LineItems>
    <LineItem ItemNumber="1">
      <Description>A Night to Remember</Description>
      <Part Id="715515009058" UnitPrice="39.95" Quantity="2"/>
    </LineItem>
  </LineItems>
</PurchaseOrder>

这真的是一种可能的情况吗?

如果有可能的话,任何人都可以给我查询吗。

提前致谢。

1 个答案:

答案 0 :(得分:0)

以下查询对我有用。

UPDATE TABLENAME dd SET dd.object_value =  
insertXMLbefore(dd.object_value,   
'/c:PurchaseOrder/c:Reference',  
XMLType('<d:sender xmlns:d="http://www.w3.org/2001/XMLSchema-instance">XXXX</d:sender>'),  
xmlns:c="http://www.w3.org/2001/XMLSchema-instance"')
WHERE dd.id in (SELECT dd.id FROM TABLENAME dd,XMLTable(XMLNAMESPACES(
DEFAULT 'http://www.w3.org/2001/XMLSchema-instance' AS "c"),
'/PurchaseOrder' PASSING dd.object_value COLUMNS  sender VARCHAR2(8 CHAR) PATH 'c:PurchaseOrder/c:Reference/text()',
rp VARCHAR2(8 CHAR) PATH 'CostCenter/text()') li
WHERE sender is null and rp = 'S30');