Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Schema parser

Status
Not open for further replies.

hixhix

Programmer
Apr 24, 2007
2
CA
Hi,

I'm using Java to develop a XML-related application. One thing I need to do is that, given a XML Schema, I need to find all the element names and their types, attributes and types of attributes.

For example, if the given schema is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="
<xs:element name="enterprise" type="EnterpriseType"/>

<xs:complexType name="EnterpriseType">
<xs:sequence>
<xs:element name="d1" type="DepartmentType"/>
<xs:element name="d2" type="DepartmentType"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="DepartmentType">
<xs:sequence>
<xs:element name="employee" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>

</xs:schema>

Then all the elelements are:

enterprise (Type: EnterpriseType)
d1 (Type: DepartmentType, Attribute: name (Type: xs:string))
d2 (Type: DepartmentType, Attribute: name (Type: xs:string))
employee (Type: xs:string)

I tried XSOM but it only iterates the top-level elelmenents/types in the schema, I couldnt go to lower level of the schema tree.

Anyone know how I could solve this problem ? Thank you very much.
 
I am certainly no expert, but I think XSOM and the XSSchemaSet object model have everything you need.

So, a higher level question: Why are you trying to do this? (Perhaps there's a better way than grinding on the XML Schema definition.)

Tom Morrison
 
I tried to use XSSchemaSet, but I can iterates all the top-level component in the set only using iterateAttGroupDecls(), iterateAttributeDecls()
iterateComplexTypes(), iterateElementDecls()... and such APIs. I could access to the lower-level components.

I'm looking for something like getChildNodes() in order to go further but I couldnt find such API.

The reason I need to do things like this is because I'm implementing some algorithm on XML. The algorithm reads the schema, read user-defined rules indicating which components to be encrypted. Then it reads a valid XML document against the schema, follows the rules and encrypt some specific components in the XML document.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top