Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

XQuery/Inserting and Updating Attributes

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Motivation You want to insert or update attributes in a document. (Note: The XQuery Update syntax below is specific to eXist and is not necessarily identical to that in the W3C XQuery Update spec. Full documentation of eXist's XQuery Update syntax can be found at http://exist-db.org/exist/apps/doc/update_ext.xml) Example Input Document <root> <message>Hello World</message> </root> Example of Attribute Insert To insert a new attribute with the name of "foo" and a value of "bar" you an use the following example: xquery version "1.0"; let $doc := doc('/db/test.xml')/root let $update := update insert attribute foo {'bar'} into $doc return $doc This will add a foo="bar" attribute to the root element Result Document <root foo="bar"> <message>Hello World</message> </root> Example of Attribute Update let $doc := doc('/db/test/update-attribute/root.xml')/root return update value $doc/@foo with 'new-value' Result Document <root foo="new-value"> <message>Hello World</message> </root>