J
Jari Kujansuu
I can successfully parse XML document using SAX or DOM and I can also
validate
XML document against schema.
Problem is that my program should deal with user-defined schemas which means
that when I parse some element from XML document I don't know until
runtime the
type of the element (it depends on the type used in user-defined
schema). XML
parser obviously validates that the value of the element is correct type but
still I receive that data in string format from parser and question is
now how
can I convert it to correct java type representation? What I need is the
type
of the element defined by schema, but can I get that somehow when I am
handling
data received by callback methods of ContentHandler in SAX or can I
found the
type information somewhere from DOM tree?
Simple example:
If schema contains something like this:
<element name="id" type="integer"/>
And corresponding XML document contains something like this
<id>15</id>
Now Parser returns the value of id element as a string representation
"15" and
I would like to find out the type defined by schema in this case
"integer" and
based on that information convert string "15" to integer value 15. How can I
do this? Parser have to get this type information anyway to validate
that data
in XML document is correct but I cannot find any ways to get that
information
out of parser to my own application code.
validate
XML document against schema.
Problem is that my program should deal with user-defined schemas which means
that when I parse some element from XML document I don't know until
runtime the
type of the element (it depends on the type used in user-defined
schema). XML
parser obviously validates that the value of the element is correct type but
still I receive that data in string format from parser and question is
now how
can I convert it to correct java type representation? What I need is the
type
of the element defined by schema, but can I get that somehow when I am
handling
data received by callback methods of ContentHandler in SAX or can I
found the
type information somewhere from DOM tree?
Simple example:
If schema contains something like this:
<element name="id" type="integer"/>
And corresponding XML document contains something like this
<id>15</id>
Now Parser returns the value of id element as a string representation
"15" and
I would like to find out the type defined by schema in this case
"integer" and
based on that information convert string "15" to integer value 15. How can I
do this? Parser have to get this type information anyway to validate
that data
in XML document is correct but I cannot find any ways to get that
information
out of parser to my own application code.