xml - Removing node using XQuery Update -


i trying remove child node parent node using xquery. say, have entry shown below in xml:

 <entry>         <id>36</id>         <title>engineering village author tool</title>         <updated>2009-09-30t12:55:42z</updated>         <libx:libapp>           <libx:entry xmlns:libx="http://libx.org/xml/libx2" src="37"/>         </libx:libapp>       </entry> 

how delete child node

<libx:entry xmlns:libx="http://libx.org/xml/libx2" src="37"/> 

i using following xquery code:

declare namespace libx='http://libx.org/xml/libx2'; declare namespace atom='http://www.w3.org/2005/atom'; declare variable $child_id xs:string external; declare variable $parent_id xs:string external; declare variable $doc_name xs:string external; declare variable $feed      xs:anyatomictype := doc($doc_name)/atom:feed; let $parent_entry := $feed/atom:entry[atom:id=$parent_id] return delete node $parent_entry//libx:entry[@libx:src=$child_id] 

the values of variables passed here are: child_id = 37 parent_id = 36 doc_name = name of document being used

i guessing wrong either way using namespaces or xpath expression using in xquery @ line :

return delete node $parent_entry//libx:entry[@libx:src=$child_id] 

please me fix this.

you declaring $feed xs:anyatomictype, setting , using node().

i'm suprised query compiles. try removing xs:anyatomictype or replacing element().

also want @src select child node, not @libx:src. so

declare namespace libx='http://libx.org/xml/libx2'; declare namespace atom='http://www.w3.org/2005/atom'; declare variable $child_id xs:string external; declare variable $parent_id xs:string external; declare variable $doc_name xs:string external; declare variable $feed := doc($doc_name)/atom:feed; let $parent_entry := $feed/atom:entry[atom:id=$parent_id] return delete node $parent_entry//libx:entry[@src=$child_id] 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -