0

I'm trying to insert a new XML element in my XML data type, but this new XML element must contain the value of another XML element. For example, given the following XML:

<Config>
    <SomeOtherNode>
        <ValueToUse>123</ValueToUse>
    </SomeOtherNode>
</Config>

should render the following:

<Config>
    <Node1>123</Node1>
    <SomeOtherNode>
        <ValueToUse>123</ValueToUse>
    </SomeOtherNode>
</Config>

I've attempted the following with no luck (it inserts the XQuery as the actual value):

update Table
set Column.modify('insert <Node1>//SomeOtherNode/ValueToUse/text()</Node1> as first into /Config')

1 Answer 1

1

XQuery uses curly braces to denote enclosed expressions, distinguishing the content expression from literal text. To fix your query, surround the enclosed expression with curly braces:

<Node1>{ //SomeOtherNode/ValueToUse/text() }</Node1>

(The whitespace inside the curly braces is just for visual clarity and isn't needed.)

The purpose of curly braces is defined in the spec at https://www.w3.org/TR/xquery-31/#doc-xquery31-EnclosedExpr:

Definition: An enclosed expression is an instance of the EnclosedExpr production, which allows an optional expression within curly braces.

EnclosedExpr       ::=      "{" Expr? "}"

Definition: In an enclosed expression, the optional expression enclosed in curly braces is called the content expression.

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

2 Comments

Dude, you are a legend
Happy to help, Rudolf!

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.