1

Consider I have two xmls, xmlA & xmlB, and I want to update the 'text content' of xmlA/abc with xmlB/bcd.

xmlA:

<root>
<abc>texas</abc>
</root>

xmlB:

<root>
<abc>kansas</abc>
</root>

If I use xdmp:node-replace(xmlA/abc/text(), xmlB/bcd/text()), the node is getting changed and not the node content. That is xmlA:

<root>
<bcd>kansas</bcd>
</root>

But I want to change only node's content. The desired output is: xmlA:

<root>
<abc>kansas</abc>
</root>

can someone tell me how to do this (without xpath 3.0)? Thanks (Ranjan).

4

2 回答 2

2

Which version of MarkLogic are you running? I tested the following in version 6.0-1.1, and that seems to work as expected. When I retrieve the stored docs after the node-replace, I get 'kansas' twice, but the inner element of 'a.xml' is untouched:

xdmp:document-insert(
    'a.xml',
    <root>
        <abc>texas</abc>
    </root>
),
xdmp:document-insert(
    'b.xml',
    <root>
        <bcd>kansas</bcd>
    </root>
);

doc('a.xml'),
doc('b.xml');

xdmp:node-replace(
    doc('a.xml')/root/abc/text(),
    doc('b.xml')/root/bcd/text()
);

doc('a.xml'),
doc('b.xml')

If you are running an old version of MarkLogic, then it is probably a bug that has been fixed since..

HTH!

于 2013-01-22T07:58:42.350 回答
1

Try this :

xdmp:node-replace(
    xmlA/abc,
    element { "abc" } { xmlB/bcd/text() }
)
于 2013-01-22T14:37:16.473 回答