getBooleanValue (DOMElement - JavaScript)

Gets the boolean value of a data element.

Defined in

DOMElement

Syntax

getBooleanValue() : boolean

getBooleanValue(xpath:string) : boolean

getBooleanValue(xpath:string, selectionNS:NamespaceContext) : boolean

Parameters Description
xpath The XPath of an element associated with the document.
selectionNS A namespace context.
Return value Description
boolean The boolean value of the element.

Usage

This method is equivalent to getBooleanValue in DOMDocument.

In a schema, this data element should be defined as boolean. In the data properties, the display type of a bound field should be String; the value is displayed as true or false.

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 button onclick event gets the boolean 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.getBooleanValue();
	} 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>
  <element1>true</element1>
</schema0>
(2) This button onclick event gets the boolean 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.getBooleanValue("/schema0/element1");
		
	} else {
		requestScope.msg = "No such document";
	}
} else {
	requestScope.msg = "No documents in database";
}
(3) This button onclick event gets the boolean 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.getBooleanValue("/p:schema0/p:element1", ns);
		
	} else {
		requestScope.msg = "No such document";
	}
} else {
	requestScope.msg = "No documents in database";
}