Index Changes

Difference between version and version     

Back to Create A Custom Structure And Test It, or Create A Custom Structure And Test It Info


At line 7 changed 1 line.
* Right click on the project and choose “New -> XML Schema…”
* Right click on the Source Packages (let's use "com.sun.customeencoder" for example), and choose "New -> XML Schema..."
At line 9 changed 1 line.
* Let’s name this custom defined structure as “customDefined1”. This will create the customDefined1.xsd file in the specified location.
* Let’s name this custom defined structure as "customDefined1”. This will create the customDefined1.xsd file in the specified location.
At line 13 changed 1 line.
* Make sure the “Apply to All Referenced Schemas” checkbox is checked.
* Make sure the "Apply to All Referenced Schemas" checkbox is checked.
At line 15 changed 1 line.
* 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.
* As an example, we have following structure defined:
At line 17 changed 1 line.
Following is the “Design” view of this custom defined structure.
the root node contains 2 groups nodes "group1" and "group2" which are delimited by the delimiter of ‘|’.
At line 19 changed 1 line.
[{Image src='image5.png'align='top' }]
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.
At line 21 changed 1 line.
The actual XSD content is as follows:
Following is the "Design” view of this custom defined structure.
At line 23 removed 159 lines.
{{{
<?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:
\\
[{Image src='image6.png'align='top' }]
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”.
[{Image src='image7.png'align='top' }]
* Then launch the tester by right clicking on the xsd and selecting "Encoding -> Test".
[{Image src='image8.png'align='top' }]
* Select input data file “customDefined1.dat” in the "Test Encoding" dialog.
[{Image src='image9.png'align='top' }]
* After successful decoding, you should see the decoded XML output as “customDefined1.xml"
[{Image src='imageA.png'align='top' }]
\\
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¡­¡±
[{Image src='image1.png'align='top' }]
* Let¡¯s name this custom defined structure as ¡°customDefined1¡±. This will create the customDefined1.xsd file in the specified location.
[{Image src='image2.png'align='top' }]
* Apply custom encoding by right clicking on the created meta xsd file and selecting "Encoding -> Apply Custom Encoding".
[{Image src='image3.png'align='top' }]
* Make sure the ¡°Apply to All Referenced Schemas¡± checkbox is checked.
[{Image src='image4.png'align='top' }]
* 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.
\\
At line 294 changed 1 line.
The root node is selected as the ¡°Top¡± node, and there are 2 levels of delimiters defined there as follows:
The root node is selected as the "Top” node, and there are 2 levels of delimiters defined there as follows:
At line 303 changed 1 line.
* As an example, we create a text delimited input data file ¡°customDefined1.dat¡± with data ¡°a,b|0123456789|abcde12345ABCDE¡±.
* As an example, we create a text delimited input data file "customDefined1.dat” with data "a,b|0123456789|abcde12345ABCDE”.
At line 307 changed 1 line.
* Select input data file ¡°customDefined1.dat¡± in the "Test Encoding" dialog.
* Select input data file "customDefined1.dat” in the "Test Encoding" dialog.
At line 309 changed 1 line.
* After successful decoding, you should see the decoded XML output as ¡°customDefined1.xml"
* After successful decoding, you should see the decoded XML output as "customDefined1.xml"

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-5) was last changed on 19-Nov-08 22:18 PM, -0800 by LixinTang