setStringValue (DOMDocument - JavaScript)
Sets the string value of an element.
Defined in
DOMDocumentSyntax
setStringValue(xpath:string, value:string) : void
setStringValue(xpath:string, value:string, selectionNS:NamespaceContext)
: void
Parameters | Description |
---|---|
xpath |
XPath of an element in the document. |
value |
The value to be set. |
selectionNS |
A namespace context. |
Usage
This method is equivalent to the XPath signatures of setStringValue in DOMElement.In a schema,
this data element should be defined as string
. In
the data properties, the display type of a bound field should be String
.
This
method generates a hierarchy of elements to meet the XPath specification.
For example, the specification
setStringValue("/schema1/element0",
"myvalue")
generates the following XML:<schema0>
<element0>myvalue</element0>
</schema0>
This method replaces all content including child nodes. Append child nodes after calling this method, not before.
If
the XPath includes namespace prefixes, either:
- Define the namespaces in the third parameter, first creating a new DOMNamespaceContextImpl object and adding the namespaces with addNamespace.
- Define the namespaces with setSelectionNamespaces before using this method without the third parameter.
Examples
(1) This example is for theonclick
event
of a button. It creates a document and sets a value. The requestScope
variable
is bound to an edit box on the page so the user specifies s
before
clicking the button.var doc = database.createNewDocument();
doc.setStringValue("/schema1/element0", requestScope.s);
doc.save()
(2) This example is for the
onclick
event
of a button. It creates a document and sets a value using namespaces.
The requestScope
variable is bound to an edit box
on the page so the user specifies s
before clicking
the button.var doc = database.createNewDocument();
var dom = doc.getDOM();
var ns = new NamespaceContextImpl();
ns.addNamespace("s", "http://mynamespace.com");
dom.setStringValue("/s:schema1/s:element0", requestScope.s, ns);
doc.save()