>>>>> "Jari" == Jari Kujansuu <ja***********@nokia.com> writes:
Jari> I can successfully parse XML document using SAX or DOM and I can also
Jari> validate
Jari> XML document against schema. Problem is that my program should deal
Jari> with user-defined schemas which means that when I parse some element
Jari> from XML document I don't know until runtime the
Jari> type of the element (it depends on the type used in user-defined
Jari> schema). XML
Jari> parser obviously validates that the value of the element is correct
Jari> type but still I receive that data in string format from parser and
Jari> question is now how
Jari> can I convert it to correct java type representation? What I need is
Jari> the type
Jari> of the element defined by schema, but can I get that somehow when I am
Jari> handling
Jari> data received by callback methods of ContentHandler in SAX or can I
Jari> found the
Jari> type information somewhere from DOM tree?
Jari> Simple example:
Jari> If schema contains something like this:
Jari> <element name="id" type="integer"/>
Jari> And corresponding XML document contains something like this
Jari> <id>15</id>
Jari> Now Parser returns the value of id element as a string representation
Jari> "15" and
Jari> I would like to find out the type defined by schema in this case
Jari> "integer" and
Jari> based on that information convert string "15" to integer value 15. How
Jari> can I do this? Parser have to get this type information anyway to
Jari> validate that data
Jari> in XML document is correct but I cannot find any ways to get that
Jari> information
Jari> out of parser to my own application code.
So did you mean that you get first the XML-data and then the schema? Or, you
did not get any schema, but like to add some information to your data?
You could use same as SOAP, namely add namespaces
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
and use <id xsi:type="xsd:int">15</id>.
Then, you can parse the xsi:type attributes and check the type.
--
Arto V. Viitanen
av@cs.uta.fi
University of Tampere, Department of Computer Sciences
Tampere, Finland
http://www.cs.uta.fi/~av/