XItemFactory を使用した項目およびシーケンスの作成
XItemFactory を使用して、新しい項目およびさまざまなタイプの項目のシーケンスを作成できます。
手順
- XFactory クラスの getItemFactory メソッドを使用して、XItemFactory のインスタンスを作成し、
適切な項目メソッドを呼び出して、特定のタイプの項目を作成します。
項目自体は、ノードまたはアトミック値 (整数、ストリング、ブールなど) にすることができます。
以下は、XItemFactory を使用してさまざまなタイプの新しい項目を作成する例です。// Create an XFactory XFactory factory = XFactory.newInstance(); // Create an XItemFactory XItemFactory itemFactory = factory.getItemFactory(); // Create a new atomic item of a type which is the default mapping of the xs:string built-in type to java.lang.String XItemView stringItem = itemFactory.item("Lets see"); // Create a new atomic item of type int XItemView intItem = itemFactory.item(3, XTypeConstants.INT_QNAME); // Create a new atomic item of type boolean boolean boolValue = false; XItemView booleanItem = itemFactory.item(boolValue, XTypeConstants.BOOLEAN_QNAME); // Create Node type DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); // Parse the input file Document doc = db.parse(INPUT_File); Node node = doc.getFirstChild(); XItemView item =itemFactory.item(node) // Create a new item of complex type from a Source StreamSource source = new StreamSource(INPUT_File); XItemView complexItem = itemFactory.item(source);
例に示されているように、 項目メソッドを使用する際に、メソッドの値として 1 つの引数を指定してできます。タイプは、組み込まれたタイプ と Java™ タイプとの間のマッピング規則に基づいて評価されます。
- XFactory クラスの getItemFactory メソッドを使用して XItemFactory のインスタンスを作成し、
適切なシーケンス・メソッドを呼び出して、シーケンス内の項目へのカーソル・アクセスを提供する、
項目のシーケンスを表す XSequenceCursor を作成します。 以下は、XItemFactory を使用して同種のシーケンスを作成する例です。
// Create an XFactory XFactory factory = XFactory.newInstance(); // Create an XItemXFactory XItemFactory itemFactory =xfactory.getItemFactory(); //Create a sequence of int values XSequenceCursor intSeq = xfactory.sequence(new int[]{1,2,3}); //Create a sequence of String values XSequenceCursor stringSeq = xfactory.sequence(new String[]{"This", "is", "a", "test"},XTypeConstants.STRING_QNAME );
以下は、XItemFactory を使用して、 さまざまなタイプの項目のシーケンスを作成する例です。// Create an XFactory XFactory factory = XFactory.newInstance(); // Create an XItemXFactory XItemFactory itemFactory = factory.getItemFactory(); //Create an Array of the newly created items XItemView[] items = new XItemView[2]; items[0] =itemFactory.item(boolValue, XTypeConstants.BOOLEAN_QNAME); items[1] = itemFactory.item(intValue, XTypeConstants.INT_QNAME); // Create a sequence of items XSequenceCursor seq = itemFactory.sequence(items);


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=txml_xitemfact
ファイル名:txml_xitemfact.html