getBooleanValue (DOMElement - JavaScript)

データエレメントのブール値を取得します。

定義場所

DOMElement

構文

getBooleanValue() : boolean

getBooleanValue(xpath:string) : boolean

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

パラメータ 説明
xpath 文書に関連付けられたエレメントの XPath です。
selectionNS namespace コンテキストです。
戻り値 説明
boolean エレメントのブール値。

使用法

このメソッドは DOMDocumentgetBooleanValue と 同等です。

スキーマでは、 このデータエレメントを boolean と定義する必要があります。データプロパティでは、 関連あるフィールドの表示タイプが String でなければなりません。 値は true または false として 表示されます。

このメソッドは 以下のいずれかに対して機能します。
  • 現在のエレメント (パラメータが指定されていない場合)。
  • XPath に一致する最初のエレメント。

XPath が名前空間プレフィックスを含む場合は、 第 2 パラメータで名前空間を定義し、 最初に新規の NamespaceContextImpl オブジェクトを 作成してから addNamespace で 名前空間を追加してください。

(1) このボタンの onclick イベントは、DOM の第 2 レベルにある 最初の子であるエレメントのブール値を取得します。requestScope 変数がページの 編集ボックスにバインドされているため、ユーザーが i を指定してからボタンを クリックすると、y または 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";
}
アクセスする文書の XML が以下のようになっている場合、 サンプルコードを実行すると 33.9 が返されます。
<schema0>
  <element1>true</element1>
</schema0>
(2) このボタンの onclick イベントは、XPath に一致する 最初のエレメントのブール値を取得します。requestScope 変数がページの 編集ボックスにバインドされているため、ユーザーが i を指定してからボタンを クリックすると、y または 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) このボタンの onclick イベントは、 名前空間を使用する XPath に一致する最初のエレメントのブール値を 取得します。requestScope 変数がページの 編集ボックスにバインドされているため、ユーザーが i を指定してからボタンを クリックすると、y または 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";
}