0

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 ShopFloorID Commented Aug 20, 2015 at 3:16

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.