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