Index Changes
This is version 4. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

Create a Custom Defined Structure and Test it



To test the custom encoder, we are about to create a sample custom defined structure which is a XSD metadata with custom encoding information. We’ll also create a sample text delimited data as input to the custom defined structure, and validate that the input data can be decoded (parsed) by the custom structure defined by launching the Encoder Tester.

(A) Create a Custom Defined Structure

  • Right click on the project and choose “New -> XML Schema…”
  • Let’s name this custom defined structure as “customDefined1”. This will create the customDefined1.xsd file in the specified location.
  • Apply custom encoding by right clicking on the created meta xsd file and selecting "Encoding -> Apply Custom Encoding".
  • Make sure the “Apply to All Referenced Schemas” checkbox is checked.
  • As an example, we have following structure defined: the root node contains 2 groups nodes “group1” and “group2” which are delimited by the delimiter of ‘|’. The first group node “group1” contains 2 delimited fields “delimited1” and “delimited2” which are delimited by the delimiter of ‘,’, and the second group node “group2” contains 2 fixed-length fields “fixed1” and “fixed2” which are 10 and 15 bytes long, respectively) with custom encoding information.

Following is the “Design” view of this custom defined structure.

The actual XSD content is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://xml.netbeans.org/schema/customDefined1"
            xmlns:tns="http://xml.netbeans.org/schema/customDefined1"
            elementFormDefault="qualified" xmlns:enc="urn:com.sun:encoder">
    <xsd:annotation>
        <xsd:appinfo source="urn:com.sun:encoder">
            <enc:encoding name="Custom Encoding" namespace="urn:com.sun:encoder-custom-1.0" style="customencoder-1.0"/>
        </xsd:appinfo>
    </xsd:annotation>
    <xsd:element name="root">
        <xsd:annotation>
            <xsd:appinfo source="urn:com.sun:encoder">
                <urn:top xmlns:urn="urn:com.sun:encoder">true</urn:top>
                <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                    <urn:nodeType>group</urn:nodeType>
                    <urn:delimiterSet>
                        <urn:level>
                            <urn:delimiter>
                                <urn:kind>normal</urn:kind>
                                <urn:precedence>10</urn:precedence>
                                <urn:optionalMode>never</urn:optionalMode>
                                <urn:terminatorMode>never</urn:terminatorMode>
                                <urn:bytes>
                                    <urn:constant>|</urn:constant>
                                </urn:bytes>
                            </urn:delimiter>
                        </urn:level>
                        <urn:level>
                            <urn:delimiter>
                                <urn:kind>normal</urn:kind>
                                <urn:precedence>10</urn:precedence>
                                <urn:optionalMode>never</urn:optionalMode>
                                <urn:terminatorMode>never</urn:terminatorMode>
                                <urn:bytes>
                                    <urn:constant>,</urn:constant>
                                </urn:bytes>
                            </urn:delimiter>
                        </urn:level>
                    </urn:delimiterSet>
                </urn:nodeProperties>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="group1">
                    <xsd:annotation>
                        <xsd:appinfo source="urn:com.sun:encoder">
                            <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                <urn:nodeType>delimited</urn:nodeType>
                            </urn:nodeProperties>
                        </xsd:appinfo>
                    </xsd:annotation>
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="delimited1" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder"/>
                                </xsd:annotation>
                            </xsd:element>
                            <xsd:element name="delimited2" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder"/>
                                </xsd:annotation>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="group2">
                    <xsd:annotation>
                        <xsd:appinfo source="urn:com.sun:encoder">
                            <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                <urn:nodeType>delimited</urn:nodeType>
                            </urn:nodeProperties>
                        </xsd:appinfo>
                    </xsd:annotation>
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="fixed1" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder">
                                        <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                            <urn:nodeType>fixedLength</urn:nodeType>
                                            <urn:length>10</urn:length>
                                        </urn:nodeProperties>
                                    </xsd:appinfo>
                                </xsd:annotation>
                            </xsd:element>
                            <xsd:element name="fixed2" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder">
                                        <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                            <urn:nodeType>fixedLength</urn:nodeType>
                                            <urn:length>15</urn:length>
                                        </urn:nodeProperties>
                                    </xsd:appinfo>
                                </xsd:annotation>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

The root node is selected as the “Top” node, and there are 2 levels of delimiters defined there as follows:
You can click on the double-down arrow to validate the customDefine1.xsd for XML conformity.

(B) Launch the Encoder Tester


Launch the Encoder Tester to test customDefine1.xsd on an input data.
  • As an example, we create a text delimited input data file “customDefined1.dat” with data “a,b|0123456789|abcde12345ABCDE”.
  • Then launch the tester by right clicking on the xsd and selecting "Encoding -> Test".
  • Select input data file “customDefined1.dat” in the "Test Encoding" dialog.
  • After successful decoding, you should see the decoded XML output as “customDefined1.xml"

The actual XML content may look like the following (after formatted):
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://xml.netbeans.org/schema/customDefined1" xsi:schemaLocation="http://xml.netbeans.org/schema/customDefined1 C:/LixinWorkSpace/InvokeEncodersInJavaSE/src/customDefined1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group1>
        <delimited1>a</delimited1>
        <delimited2>b</delimited2>
    </group1>
    <group2>
        <fixed1>0123456789</fixed1>
        <fixed2>abcde12345ABCDE</fixed2>
    </group2>
</root>

Create a Custom Defined Structure and Test it



To test the custom encoder, we are about to create a sample custom defined structure which is a XSD metadata with custom encoding information. We¡¯ll also create a sample text delimited data as input to the custom defined structure, and validate that the input data can be decoded (parsed) by the custom structure defined by launching the Encoder Tester.

(A) Create a Custom Defined Structure

  • Right click on the project and choose ¡°New -> XML Schema¡­¡±
  • Let¡¯s name this custom defined structure as ¡°customDefined1¡±. This will create the customDefined1.xsd file in the specified location.
  • Apply custom encoding by right clicking on the created meta xsd file and selecting "Encoding -> Apply Custom Encoding".
  • Make sure the ¡°Apply to All Referenced Schemas¡± checkbox is checked.
  • As an example, we have following structure defined: the root node contains 2 groups nodes ¡°group1¡± and ¡°group2¡± which are delimited by the delimiter of ¡®|¡¯. The first group node ¡°group1¡± contains 2 delimited fields ¡°delimited1¡± and ¡°delimited2¡± which are delimited by the delimiter of ¡®,¡¯, and the second group node ¡°group2¡± contains 2 fixed-length fields ¡°fixed1¡± and ¡°fixed2¡± which are 10 and 15 bytes long, respectively) with custom encoding information.

Following is the ¡°Design¡± view of this custom defined structure.

The actual XSD content is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://xml.netbeans.org/schema/customDefined1"
            xmlns:tns="http://xml.netbeans.org/schema/customDefined1"
            elementFormDefault="qualified" xmlns:enc="urn:com.sun:encoder">
    <xsd:annotation>
        <xsd:appinfo source="urn:com.sun:encoder">
            <enc:encoding name="Custom Encoding" namespace="urn:com.sun:encoder-custom-1.0" style="customencoder-1.0"/>
        </xsd:appinfo>
    </xsd:annotation>
    <xsd:element name="root">
        <xsd:annotation>
            <xsd:appinfo source="urn:com.sun:encoder">
                <urn:top xmlns:urn="urn:com.sun:encoder">true</urn:top>
                <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                    <urn:nodeType>group</urn:nodeType>
                    <urn:delimiterSet>
                        <urn:level>
                            <urn:delimiter>
                                <urn:kind>normal</urn:kind>
                                <urn:precedence>10</urn:precedence>
                                <urn:optionalMode>never</urn:optionalMode>
                                <urn:terminatorMode>never</urn:terminatorMode>
                                <urn:bytes>
                                    <urn:constant>|</urn:constant>
                                </urn:bytes>
                            </urn:delimiter>
                        </urn:level>
                        <urn:level>
                            <urn:delimiter>
                                <urn:kind>normal</urn:kind>
                                <urn:precedence>10</urn:precedence>
                                <urn:optionalMode>never</urn:optionalMode>
                                <urn:terminatorMode>never</urn:terminatorMode>
                                <urn:bytes>
                                    <urn:constant>,</urn:constant>
                                </urn:bytes>
                            </urn:delimiter>
                        </urn:level>
                    </urn:delimiterSet>
                </urn:nodeProperties>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="group1">
                    <xsd:annotation>
                        <xsd:appinfo source="urn:com.sun:encoder">
                            <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                <urn:nodeType>delimited</urn:nodeType>
                            </urn:nodeProperties>
                        </xsd:appinfo>
                    </xsd:annotation>
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="delimited1" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder"/>
                                </xsd:annotation>
                            </xsd:element>
                            <xsd:element name="delimited2" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder"/>
                                </xsd:annotation>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="group2">
                    <xsd:annotation>
                        <xsd:appinfo source="urn:com.sun:encoder">
                            <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                <urn:nodeType>delimited</urn:nodeType>
                            </urn:nodeProperties>
                        </xsd:appinfo>
                    </xsd:annotation>
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="fixed1" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder">
                                        <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                            <urn:nodeType>fixedLength</urn:nodeType>
                                            <urn:length>10</urn:length>
                                        </urn:nodeProperties>
                                    </xsd:appinfo>
                                </xsd:annotation>
                            </xsd:element>
                            <xsd:element name="fixed2" type="xsd:string">
                                <xsd:annotation>
                                    <xsd:appinfo source="urn:com.sun:encoder">
                                        <urn:nodeProperties xmlns:urn="urn:com.sun:encoder-custom-1.0">
                                            <urn:nodeType>fixedLength</urn:nodeType>
                                            <urn:length>15</urn:length>
                                        </urn:nodeProperties>
                                    </xsd:appinfo>
                                </xsd:annotation>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

The root node is selected as the ¡°Top¡± node, and there are 2 levels of delimiters defined there as follows:
You can click on the double-down arrow to validate the customDefine1.xsd for XML conformity.

(B) Launch the Encoder Tester


Launch the Encoder Tester to test customDefine1.xsd on an input data.
  • As an example, we create a text delimited input data file ¡°customDefined1.dat¡± with data ¡°a,b|0123456789|abcde12345ABCDE¡±.
  • Then launch the tester by right clicking on the xsd and selecting "Encoding -> Test".
  • Select input data file ¡°customDefined1.dat¡± in the "Test Encoding" dialog.
  • After successful decoding, you should see the decoded XML output as ¡°customDefined1.xml"

The actual XML content may look like the following (after formatted):
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://xml.netbeans.org/schema/customDefined1" xsi:schemaLocation="http://xml.netbeans.org/schema/customDefined1 C:/LixinWorkSpace/InvokeEncodersInJavaSE/src/customDefined1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group1>
        <delimited1>a</delimited1>
        <delimited2>b</delimited2>
    </group1>
    <group2>
        <fixed1>0123456789</fixed1>
        <fixed2>abcde12345ABCDE</fixed2>
    </group2>
</root>
  • Any questions/feebacks?
Email: soabi-encoders@sun.com

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 19-Nov-08 17:41 PM, -0800 by LixinTang