getDoubleValue (DOMElement - JavaScript)
Gets the double value of a data element.
Defined in
DOMElementSyntax
getDoubleValue() : double
getDoubleValue(xpath:string) : double
getDoubleValue(xpath:string, selectionNS:NamespaceContext)
: double
Parameters | Description |
---|---|
xpath |
The XPath of an element associated with the document. |
selectionNS |
A namespace context. |
Return value | Description |
---|---|
double |
The double value of the element. |
Usage
This method is equivalent to getDoubleValue in DOMDocument.In a schema,
this data element should be defined as double
. In
the data properties, the display type of a bound field should be Number
.
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 double 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.getDoubleValue();
} 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
33.9
.<schema0>
<element2>33.9</element2>
</schema0>
(2) This button
onclick
event
gets the double 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.getDoubleValue("/schema0/element2");
} else {
requestScope.msg = "No such document";
}
} else {
requestScope.msg = "No documents in database";
}
(3) This button
onclick
event
gets the double 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.getDoubleValue("/p:schema0/p:element2", ns);
} else {
requestScope.msg = "No such document";
}
} else {
requestScope.msg = "No documents in database";
}