getStringValue (DOMElement - JavaScript)
Gets the string value of a data element.
Defined in
DOMElementSyntax
getStringValue() : stringgetStringValue(xpath:string) : string
getStringValue(xpath:string, selectionNS:NamespaceContext)
: string
| Parameters | Description |
|---|---|
xpath |
The XPath of an element associated with the document. |
selectionNS |
A namespace context. |
| Return value | Description |
|---|---|
string |
The string value of the element. |
Usage
This method is equivalent to getStringValue in DOMDocument.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 works on either:
- The current element if no parameters are specified.
- The first element that matches the XPath.
If the XPath includes namespace prefixes, define the namespaces in the second parameter, first creating a new NamespaceContextImpl object and adding the namespaces with addNamespace.
Examples
(1) This buttononclick event
gets the string value of the element that is the first child at the
second level of the DOM. The requestScope variables
are bound to edit boxes on the page so the user specifies i before
clicking the button, and gets back y or msg.var dc = database.getAllDocuments();
if(dc.getDocumentCount() > 0) {
if(requestScope.i != null &&
requestScope.i >= 0 &&
requestScope.i < dc.getDocumentCount()) {
var ar = dc.getDocumentArray(requestScope.i + 1);
var doc = ar[i];
var schema = doc.getDocumentElement();
var elem = schema.getFirstChild();
requestScope.y = elem.getStringValue();
} else {
requestScope.msg = "No such document";
}
} else {
requestScope.msg = "No documents in database";
}If the XML of the accessed document is as follows,
the sample code returns
foo.<schema0>
<element0>foo</element0>
</schema0>(2) This button
onclick event
gets the string value of the first element that matches an XPath.
The requestScope variables are bound to edit boxes
on the page so the user specifies i before clicking
the button, and gets back y or msg.var dc = database.getAllDocuments();
if(dc.getDocumentCount() > 0) {
if(requestScope.i != null &&
requestScope.i >= 0 &&
requestScope.i < dc.getDocumentCount()) {
var ar = dc.getDocumentArray(requestScope.i + 1);
var doc = ar[i];
var elem = doc.getDocumentElement();
requestScope.y = elem.getStringValue("/schema0/element0");
} else {
requestScope.msg = "No such document";
}
} else {
requestScope.msg = "No documents in database";
}(3) This button
onclick event
gets the string value of the first element that matches an XPath that
uses a namespace. The requestScope variables are
bound to edit boxes on the page so the user specifies i before
clicking the button, and gets back y or msg.var dc = database.getAllDocuments();
if(dc.getDocumentCount() > 0) {
if(requestScope.i != null &&
requestScope.i >= 0 &&
requestScope.i < dc.getDocumentCount()) {
var ns = new NamespaceContextImpl();
ns.addNamespace("p", "http://mynamespace.com");
var ar = dc.getDocumentArray(requestScope.i + 1);
var doc = ar[i];
var elem = doc.getDocumentElement();
requestScope.y = elem.getStringValue("/p:schema0/p:element0", ns);
} else {
requestScope.msg = "No such document";
}
} else {
requestScope.msg = "No documents in database";
}