Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

As described in XML UI, Nexaweb Platform stores the state of the UI in an XML document. Depending upon the configuration of a Nexaweb-enabled application, Nexaweb platform may maintain a copy of the UI document on both the server and the client; however the client-side copy of the UI document always controls the UI.  In addition other application data may be stored in other XML documents.

These XML documents, both the UI document and application-specific documents, can be modified declaritively through the use of XUpdate along with XPath.

XUpdate - A language for modifying XML documents declaratively. This can be used to modify any existing application documents.

Xpath -     A language for addressing parts of an XML document. It is used as part of the XUpdate syntax.

This topic contains the following sections:

  • XUpdate and XPath overview
  • Creating an XUpdate page
  • Using more XUpdate commands
  • Updating an XML document using Shortcut Syntax

Note: A document as referred to in this topic means an xml document object stored in the memory unless otherwise noted.

 
XUpdate and XPath overview

XUpdate is an XML language for updating/modifying XML documents. The following example of an XUpdate page demonstrates how to create a button on the UI document:

...

languagehtml/xml
linenumberstrue
XML UI」 で説明されているように、Nexaweb Platform は UI の状態を XML ドキュメントに格納します。Nexaweb に対応したアプリケーションの設定によって異なりますが、Nexaweb Platform は、サーバーとクライアントの両方で UI ドキュメントのコピーを維持できます。ただし、この UI ドキュメントのクライアントサイドのコピーは常に UI を制御します。また、他のアプリケーションデータは他の XML ドキュメントに格納されている場合があります。
これらの XML ドキュメント、つまり UI ドキュメントとアプリケーション固有のドキュメントは、XUpdate を XPath と併用することによって宣言的に変更することができます。
XUpdate - XML ドキュメントを宣言的に変更するための言語で、既存のアプリケーションドキュメントを変更する場合に使用できます。
Xpath - XML ドキュメントの各部分をアドレス指定するための言語で、XUpdate シンタックスの一部として使用されます。
このトピックは以下のセクションから構成されています。
  • XUpdate と XPath の概要
  • XUpdate ページの作成
  • その他の XUpdate コマンドの使用
  • ショートカット シンタックスを使用した XML ドキュメントの更新
注: このトピックで「ドキュメント」という場合は、特に注釈のない限り、メモリに格納されている XML ドキュメントオブジェクトを指します。

XUpdate と XPath の概要

XUpdate は、XML ドキュメントを更新または変更するための XML 言語です。次の XUpdate ページの例では、UI ドキュメントでボタンを作成する方法を示します。

 

Code Block
<xu:modifications document="nxml" version="1.0"

...

 xmlns:xu="http://nexaweb.com/xupdate">

...

<xu:append select="/nxml/rootPane">

...

<button text="a new button"/>

...

</xu:append>
</xu:modifications>

...

 


Nexaweb Platform 4.0

...

以降のバージョンでは、すべてのメモリ内ドキュメントに名前が付けられています。Nexaweb Platform では、UI ドキュメント用に "nxml"

...

という名前が予約されています。

XUpdate

...

は XPath 式を使用して、ドキュメント内の場所を指定します。Nexaweb Platform は XPath 1.0

...

仕様に対応しています。上の例で、"/nxml/rootpane"

...

は、ドキュメントルートの <nxml> タグの子である <rootPane> タグを特定する XPath 式です。

"/nxml/rootPane"

...

は場所のパスです。評価が行われると、コンテキストノードへの相対的なノードのセットを返します。この場合は、'/'

...

となります。Nexaweb Platform では、各 UI ドキュメントは、1 つの <nxml> 要素の下に <rootPane> 要素を 1 つだけ持つことができます。つまり、"/nxml/rootPane"

...

'/child::nxml/child::rootPane[1]'

...

  • child is an example of an axis, which specifies the tree relationship between the nodes selected by the location step and the context node,
  • nxml and/or rootPane is an example of a node test, which specifies the node type and expanded-name of the nodes selected by the location step, and
  • [1] is a sample of predicates, which use arbitrary expressions to further refine the set of nodes selected by the location step.

...

の短縮形です。
  • child は軸の例で、場所のステップによって選択されたノードとコンテキスト ノード間のツリー関係を指定します。
  • nxmlrootPane はノード テストの例で、ノードの種類と、場所のステップによって選択されたノードの拡張名を指定します。
  • [1] は述語の例で、任意の式を使用して、場所のステップによって選択されたノードのセットをさらに絞り込みます。

...

You can create an XUpdate page as a static file, or as a page that server pages or servlets dynamically generate. Each XUpdate page is a well-formed XML document that contains one or more <xu:modifications> elements. If the page contains more than one <xu:modifications> elements, you must wrap those elements in a single <nxml> root node to make the page well-formed. As shown in the above example:

...

XPath の詳細については、http://www.w3.org/TR/xpath

...

を参照してください。

XUpdate ページの作成


XUpdate ページは、静的ファイル、またはサーバーページまたはサーブレットが動的に生成するページとして作成できます。各 XUpdate ページは、1 つ以上の <xu:modifications> 要素を含む、整形式の XML ドキュメントです。複数の <xu:modifications> 要素がページに含まれている場合は、1 つの <nxml> ルートノードにこれらの要素をラップして、整形式のページにする必要があります。次に、上の例で使用されているアイテムについて説明します。
  • document - 操作が実行されるドキュメントの名前を指定します。
  • xmlns:xu - specifies the namespace for the XUpdate instructions. It must be XUpdate 命令の名前空間を指定します。http://www.nexaweb.com/xupdate. を参照してください。
  • select - specifies an XPath expression that evaluates to a set of Elements, Attribute or Text objects. XUpdate statements with the exception of <create-document> require a select statement.

Sample 1: Using a jsp page to generate XUpdate statements for use as an event handler.

...

  • 要素、属性、またはテキスト オブジェクトのセットに対して評価する XPath 式を指定します。<create-document> 以外の XUpdate 文には select 文が必要です。
サンプル 1: JSP ページを使用して、イベントハンドラとして使用する XUpdate 文を生成する方法
XUpdate ページは Nexaweb のイベントハンドラとして動作します。次の例は、XML コードのスニペットと、XUpdate を使用してイベント処理を行う XML ファイルを示します。
<button text="Append Button at End" onCommand="appendButton.jsp"/>

...

appendButton.jsp

...

ファイルの全体は次のようになります。

Code Block

...

<% String newButtonName = "myNewButton"; %>
<xu:modifications document="nxml" version="1.0" 

...

xmlns:xu="http://nexaweb.com/xupdate">

...


...

<xu:append select="/nxml/rootPane">

...


<button text="<%=newButtonName%>"/>

...

</xu:append>
</xu:modifications>

...

 


サンプル 2:

...

XUpdate を使用して新規 XML ドキュメントを作成する方法
この例では、XUpdate 文により、<name> と <address> の子を持つ "nexaweb" ドキュメントが作成されます。次に、同じ変更ブロック内にある 2 番目の XUpdate 文で、<phone> の子が追加されます。作成が完了すると、com.nexaweb.xml.DocumentRegistry.findDocument()

...

を使用してこのドキュメントにアクセスできます。

 

Code Block

...

...

<xu:modifications document="nexaweb" version="1.0" xmlns:xu="http://nexaweb.com/xupdate">

...


...

<!-- 

...

create-document 

...

コマンドは最初のコマンドでなければなりません。 -->

...

<xu:create-document>

...


...

<nexaweb>

...


...

<name>Nexaweb</name>

...


<address>Cambridge</address>

...


</nexaweb>

...


...

</xu:create-document>

...

<xu:append select="/nexaweb">

...

<phone>617-577-8100</phone>

...


...

</xu:append>
</xu:modifications>

 

...

サンプル

3: MCO

...

コード
次の例では、作成された "nexaweb"

...

ドキュメントのルート要素をクライアントの MCO コード内で検出します。
Code Block

...

ClientSession session = getSession();
Document document = session.getDocumentRegistry().findDocument("nexaweb");
Element element = document.getRootElement();

...

 


XUpdate を使用した初期 UI ページの作成
XUpdate ドキュメントを使用して初期 UI ページを作成するには、次の特別な規則が適用されます。
  • 最初の XUpdate 文で、<rootPane> 要素を "/nxml" nodesノードに追加する必要があります。
  • Subsequent XUpdate statements can append to 後続の XUpdate 文では、'/nxml/rootPane' node or its children

...

  • ノードまたはその子に追加できます。
この方法は、「XUpdate を使用して新規 XML ドキュメントを作成する方法」で紹介した例と異なります。この方法の場合は、ア プリケーションを起動した直後、開発者コードが実行される前に "nxml"

...

Using XUpdate commands

XUpdate can improve your productivity in developing Nexaweb-enabled applications by allowing you to use XML documents rather than writing/compiling java code. It provides many flexible commands. This section provides a sampling of XUpdate commands along with some sample code. See the XUpdate schema reference for more information on the exact syntax and details. insert-after The following example shows the use of the insert-after command. Related commands include: insert-before, instert-at.

...

languagehtml/xml
linenumberstrue

...

UI ドキュメントが存在します。初期 UI を作成する XUpdate では、ルートとして 1 つの <nxml> タグと唯一の要素を持つ "nxml" ドキュメントが既に存在することを仮定する必要があります。

また、XUpdate に依存せずに、ShortcutSyntax (以下に詳述) を使用して、初期 UI の記述を作成することもできます。ShortcutSyntax は、同じページで XUpdate と共に使用することができます。ただし、この方法を使用する場合には、ShortcutSyntax のセクションで説明する特別な注意が必要です。一般的にはこの 2 つを一緒に使用せず、可能な場合には XUpdate だけ、または ShortcutSyntax だけを使用して初期ページを宣言することをお勧めします。

XUpdate コマンドの使用


XUpdate を使用すると、Java コードを記述またはコンパイルしないで、XML ドキュメントを使用できるため、Nexaweb に対応したアプリケーションを開発する場合に生産性が向上します。また、柔軟性のあるコマンドを数多く使用できます。ここでは、XUpdate コマンドのサンプルとそのコード例を示します。正確なシンタックスと詳細については、XUpdate スキーマのリファレンスを参照してください。

insert-after


次の例は、insert-after コマンドの使用方法を示します。関連するコマンドには、insert-before、instert-at などがあります。

 

Code Block
<xu:insert-after select="/nxml/rootPane/window[1]/panel[1]">
<panel/>
</xu:insert-after>

...

append

...

languagehtml/xml
linenumberstrue

次の例は、append コマンドの使用方法を示します。

 

Code Block
<xu:append select="/nxml/rootPane/window[1]">

...

<panel/>
</xu:append>

...

 

set-attribute

...

languagehtml/xml
linenumberstrue

次の例は、set-attribute コマンドの使用方法を示します。
関連するコマンドには、attribute、remove-attribute などがあります。

 

Code Block
<xu:set-attribute select="/nxml/rootPane/window[1]/panel[1]>

...


...

<xu:attribute name="myattr" value="myvalue" />
</xu:set-attribute>

...

 

replace-children

...

languagehtml/xml
linenumberstrue

...

次の例は、replace-children コマンドの使用方法を示します。
関連するコマンドには、replace などがあります。

 

Code Block
<xu:replace-children select="/nxml/rootPane/window[1]">
<panel/>
<panel/>
<label text="mylabel"/>
</xu:replace-children>

...

remove-element

...

Code Block
languagehtml/xml
linenumberstrue
 <xu:remove-element select="/nxml/rootPane/window[1]/panel[1]"/>

次の例は、remove-element コマンドの使用方法を示します。
関連するコマンドには、remove-attribute などがあります。

<xu:remove-element

...

select="/nxml/rootPane/window[1]/panel[1]"/>

...

variable, value-of

...

languagehtml/xml
linenumberstrue

次の例は、value-of 変数コマンドの使用方法を示します。

 

Code Block
<xu:variable name="myvar" select="/nxml/rootPane/window[1]/panel[1]" clone="true"/>
<xu:append select="/nxml/rootPane/window[1]">

...

<xu:value-of name="myvar"/>
</xu:append>

clone The following example shows the use of the clone command.

...

languagehtml/xml
linenumberstrue

 

clone

次の例は、clone コマンドの使用方法を示します。

<xu:clone

...

select="/nxml/rootPane/window[1]"

...

deep="true"

...

/>
 

Updating an XML document using the Shortcut Syntax

The Shortcut Syntax allows you to:

  • Declare the initial UI for your application without relying on XUpdate statements
  • Display windows and dialogs in the <rootPane> without XUpdate

The Shortcut Syntax essentially provides a shorthand notation for using an XUpdate statement that appends to the <rootPane> tag. A page uses shortcut syntax notation if all of the following apply:

  • The page has NXML tags not wrapped in XUpdate
  • The page is not being included by an <include> tag
  • The page is the first page of the application, or the page has a <window>, <dialog> or <messageDialog> as the root element (and is not a wrapping "nxml" tag)

The Nexaweb platform uses the following rules when it processes a page in shortcut notation:

  • If the page does not have a <rootPane> tag and the UI document does not yet include a rootPane, Nexaweb creates the rootPane tag and adds it to the UI document under the root <nxml> tag. Nexaweb then adds the contents of the page to this newly created <rootPane>. This is the only scernario under which Nexaweb automatically creates <rootPane>.
  • If the page does have a <rootPane> tag, Nexaweb automatically appends that tag to the root <nxml> tag of the application. However, if the UI document already has a <rootPane> this will produce two root panes and lead to an error in the application.

Nexaweb considers any page with NXML not wrapped in XUpdate or included by an <include> tag to be shortcut syntax. The following example presents some different ways of declaring the initial UI using the shortcut notation. index.nxml - the start page

...

languagehtml/xml
linenumberstrue

...


ショートカットシンタックスを使用した XML ドキュメントの更新

ショートカットシンタックスの特徴は次のとおりです。
  • XUpdate 文に依存することなく、アプリケーションの初期 UI を宣言する
  • XUpdate を使用せずに、ウィンドウとダイアログを <rootPane> に表示する
本来、ショートカットシンタックスは、<rootPane> タグに追加する XUpdate 文を使用する場合に簡便な表記法を提供するものです。
次の項目にすべて該当する場合、ショートカットシンタックスの表記法が使用されます。
  • XUpdate でラップされていない NXML タグが対象ページにある
  • 対象ページが <include> タグでインクルードされていない
  • 対象ページがアプリケーションの最初のページであるか、<window>、<dialog>、または <messageDialog> をルート要素として持つ (また、ラップされる "nxml" タグではない)
Nexaweb Platform では、次の規則に従って、ショートカット表記法でページが処理されます。
  • <rootPane> タグがページになく、rootPane が UI ドキュメントでインクルードされていない場合は、rootPane タグが作成され、ルートの <nxml> タグの下にある UI ドキュメントに追加されます。次に、ページのコンテンツが、新たに作成された <rootPane> に追加されます。この処理は、Nexaweb で <rootPane> が自動的に作成される場合にのみ行われます。
  • <rootPane> タグがページにない場合は、このタグがアプリケーションのルートの <nxml> タグに自動的に追加されます。ただし、<rootPane> が既に UI ドキュメントにある場合は、ルート ペインが 2 つ作成されるため、アプリケーションでエラーが発生します。
NXML タグが XUpdate でラップされていないページや <include> タグによってインクルードされていないページがあると、そのページはショートカットシンタックスであるとみなされます。次に、このショートカット表記法を 使用して初期 UI を宣言する例をいくつか示します。
index.nxml - 起動ページ
 
Code Block
<!-- rootPane をルートの "nxml" タグに追加します。 -->
<rootPane>
<label text="hello world"/>
  <button text="click for hello world window" onCommand="window.nxml"/>
</rootPane>

...

 
または
Code Block

...

languagehtml/xml
linenumberstrue
<--

...

 

...

rootPane 

...

を自動的に作成して 

...

"nxml" 

...

タグに追加し、ラベルとボタンをそのルートペインの下に配置します。 -->
<nxml>

...


...

<label text="hello world"/>

...

<button text="click for hello world window" onCommand="window.xml"/>
</nxml>

...

または

Code Block

...

languagehtml/xml
linenumberstrue
<!--

...

 

...

rootPane 

...

を自動的に作成して "nxml" 

...

タグに追加し、その下にボタンを配置します。 -->
<!-- 

...

起動ページのこのシンタックスでは、要素を 

...

1 つだけ持つことができます。 -->
<button text="click for hello world window" onCommand="window.xml"/>

window.xml

Code Block

...

languagehtml/xml
linenumberstrue
<!-- 

...

これらのタグを直接インクルードすると、起動ページ以外のページにウィンドウ、ダイアログ、メッセージダイアログのみを挿入できます。 -->
<window caption="hello world window"/>

...

または

Code Block

...

...

<nxml>

...

<!-- 

...

これらのタグを直接インクルードすると、起動ページ以外のページにウィンドウ、ダイアログ、メッセージダイアログのみを挿入できます。 -->
<window caption="hello world window"/>
</nxml>