0
votes

I am trying to replace a node in an xml using the following code

String xquery_replace="xquery replace node CIDEM/ShopFloor/foo[/CIDEM/ShopFloor/ShopFloorID=1] with "+new_gbXML;
session.execute(xquery_replace);

So i want for example to change the foo node of the first ShopFloor node

The xml has the following content

<CIDEM>
    <ShopFloor>
        <ShopFloorID>1</ShopFloorID>
        <foo bar="2">
            <baz>there</baz>
        </foo>
    </ShopFloor>
  <ShopFloor>
      <ShopFloorID>2</ShopFloorID>
      <foo bar="5">
          <baz>there</baz>
      </foo>
  </ShopFloor>
</CIDEM>

And I am receiving the following error "[XUTY0008] Single element, text, attribute, comment or pi expected as replace target."

Any idea why?

1
The path is wrong. It should be like CIDEM/ShopFloor[ShopFloorID="1"]/foo when addressing the foo node of the FIRST ShopFloorIDJohn

1 Answers

1
votes

The error message itself is telling whats wrong.

"[XUTY0008] Single element, text, attribute, comment or pi expected as replace target."

means that it is expecting an element or text or attribute... as a target to be replaced. But the path in your query is taking it nowhere. Read my comment for proper path.

For Ex: If you want to replace the value of the attribute bar for ShopFloorID with value 1, then the path should be CIDEM/ShopFloor[ShopFlorrID="1"]/foo/@bar