You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Henry Miller <hm...@eti.com> on 2004/03/15 20:53:04 UTC

Preparsing XML Schema data types in Xerces-J

Another one from the "yet another newbie question" department...

I'm trying to preparse XML schema files and I've hit a snag that I 
just cannot figure out on my own.

Using Xerces-J, I'm able to get all the information out, except the 
element's data type. In fact, all I can get is the element name and 
nothing else.

Given the following XSD snippet:

     <element name="PriceRequest">
         <complexType>
             <all>
                 <element name="Symbol" type="string"/>
                 <element name="price" type="float"/>
             </all>
          </complexType>
     </element>

I managed to drill down through the Xerces-J methods and end up in 
the XSComplexTypeDecl class when I hit the problem. My code is 
complicated (made worse by my toying with it now), but hopefully the 
question is simple enough to answer: How can I get the data types out 
of the declared elements (as shown above) from the object context 
created by XSComplexTypeDecl? what method(s) do I need to connect 
together in order to extract it? Is there a 'set' list?

I guess that's three questions. I'm so lost... :-)

I'm able to get the element names from a particle list by parsing a 
string that returns all of them using getParticle() in 
XSComplexTypeDecl -- probably not the cleanest, but it works. Why 
doesn't XSComplexTypeDecl provide types here as well? I'm sure 
there's a reason which I don't yet see.

I'm not even sure what is relevant code to clip out for your viewing pleasure.

Any ideas?
-- 


--Henry


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Bug parsing xhtml-strict schema

Posted by Bob Foster <bo...@objfac.com>.
Neil Delima wrote:
> Hi Bob,
> 
> Seems like this has changed in the schema specification errata.  See
> http://www.w3.org/2001/05/xmlschema-errata#E2-18.

Thanks very much! (Though I don't understand why this is an "Error" - 
looks like a spec change to me unless there was a real ambiguity and not 
just a need for lookahead.) I guess we'll just be going through a period 
where half the tools accept it and half reject it, but it's good to know 
Xerces is in the more up-to-date half.

Bob

> 
> 
> Bob Foster <bo...@objfac.com> wrote on 03/17/2004 05:37:40 PM:
> 
> 
>>Xerces 2.6.0 reports an error in:
>>
>>http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd
>>
>>against this regex pattern (among others):
>>
>>     <xs:restriction base="xs:string">
>>       <xs:pattern value="[-+]?(\d+|\d+(\.\d+)?%)"/>
>>     </xs:restriction>
>>
>>Xerces is complaining about the - that begins [-+]. Yet XML Schema Part
>>2 http://www.w3.org/TR/xmlschema-2/#nt-charRange specifically allows a -
>>to begin a positive character group.
>>
>>I'm surprised Xerces gets this wrong on such a public example. Is there
>>a version where this is fixed?
>>
>>If not, can someone point to where the code that checks this is so I can
>>temporarily fix it myself? Thanks.
>>
>>Bob


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Bug parsing xhtml-strict schema

Posted by Neil Delima <nd...@ca.ibm.com>.



Hi Bob,

Seems like this has changed in the schema specification errata.  See
http://www.w3.org/2001/05/xmlschema-errata#E2-18.



Bob Foster <bo...@objfac.com> wrote on 03/17/2004 05:37:40 PM:

> Xerces 2.6.0 reports an error in:
>
> http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd
>
> against this regex pattern (among others):
>
>      <xs:restriction base="xs:string">
>        <xs:pattern value="[-+]?(\d+|\d+(\.\d+)?%)"/>
>      </xs:restriction>
>
> Xerces is complaining about the - that begins [-+]. Yet XML Schema Part
> 2 http://www.w3.org/TR/xmlschema-2/#nt-charRange specifically allows a -
> to begin a positive character group.
>
> I'm surprised Xerces gets this wrong on such a public example. Is there
> a version where this is fixed?
>
> If not, can someone point to where the code that checks this is so I can
> temporarily fix it myself? Thanks.
>
> Bob
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Bug parsing xhtml-strict schema

Posted by Bob Foster <bo...@objfac.com>.
Xerces 2.6.0 reports an error in:

http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd

against this regex pattern (among others):

     <xs:restriction base="xs:string">
       <xs:pattern value="[-+]?(\d+|\d+(\.\d+)?%)"/>
     </xs:restriction>

Xerces is complaining about the - that begins [-+]. Yet XML Schema Part 
2 http://www.w3.org/TR/xmlschema-2/#nt-charRange specifically allows a - 
to begin a positive character group.

I'm surprised Xerces gets this wrong on such a public example. Is there 
a version where this is fixed?

If not, can someone point to where the code that checks this is so I can 
temporarily fix it myself? Thanks.

Bob


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Preparsing XML Schema data types in Xerces-J

Posted by Henry Miller <hm...@eti.com>.
My code made you cringe, didn't it?  I'll spare you the rest of it then... :-)

Thanks for the tip, that cleaned it up a lot.

I'm still new to Java and Xerces-J, it would have taken me a long 
time to make the connection that getName() would return a type value. 
That's what I get for being self-taught!

Thanks again!

--H

>Hi Henry,
>
>Instead of the following:
>
>>  String dataType = partTerm.getTypeDefinition().toString();
>
>You should use the "getName()" method defined on the XSObject [1]:
>partTerm.getTypeDefinition.getName()
>partTerm.getTypeDefinition.getNamepspace()
>
>This is the "right" way to query name via API.
>
>[1]
>http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSObject
>
>Thank you,
>--
>Elena Litani / IBM Toronto
>

-- 


--Henry


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Preparsing XML Schema data types in Xerces-J

Posted by Elena Litani <el...@ca.ibm.com>.



Hi Henry,

Instead of the following:

> String dataType = partTerm.getTypeDefinition().toString();

You should use the "getName()" method defined on the XSObject [1]:
partTerm.getTypeDefinition.getName()
partTerm.getTypeDefinition.getNamepspace()

This is the "right" way to query name via API.

[1]
http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSObject

Thank you,
--
Elena Litani / IBM Toronto

Henry Miller <hm...@eti.com> wrote on 03/17/2004 04:27:59 PM:

> The good news is -- I figured out my problem. The bad news is -- I
> didn't use the code snippet. Many apologies, but thank you very much
> for the assistance.
>
> After analyzing Elena's response more closely, I saw that I only
> needed to make one more leap from what I already had. Thank you Elena
> for the final clue!
>
> I was already iterating down the "all" particles list, soooo....
>
> It turns out I needed to make the following changes in my code:
>
>     XSObject partObj = particles.getParticles().item(idx);      //
> Clue connected
>     XSParticleDecl partObj2 = (XSParticleDecl)partObj;          // me
to..
>     XSElementDecl partTerm = (XSElementDecl)partObj2.getTerm(); //
..here.
>
>     String dataType = partTerm.getTypeDefinition().toString();  //
> Elena's note
>     StringTokenizer dataTypeST =
>                         new StringTokenizer(dataType, ",", false);
>     String Trash = dataTypeST.nextToken();
>     dataType = dasTypeST.nextToken();
>
> Which gives me exactly "float" or "string" or whatever in my dataType
field!
>
> Now, you experts are probably doubling over with laughter at my code,
> but right now I think it's simply beautiful!!!  Another headache
> gone...
>
> Sorry I used internal classes. It's too much code to go back and redo
> now anyway.
>
> --Henry
>
> >Okay, I'm pasting this code snippit with two hopes: One, that it is
> >useful to the poster of the question, and two, that someone can give
> >me a textual 'slap' if the code is 'bad form', or if there are
> >better faster ways to do what I did below. The purpose of the class
> >as a whole is to get some info that I need so that I can get the
> >Grammers out of memory.
> >
> >To Henry, good luck, to everyone else, thanks :~)
> >
> >:Note_1: SchemaTools is my own little tool. All you need to care
> >about here is that it DOES return the correct XSElementDecl for
> >whatever element is passed. If there is a better way than holding on
> >to the grammers to do this I'd love to know. My memory footprint is
> >like 50MB. But that is a question for another day (like tomorrow :~)
> >
> >:Note_2:Regarding the 'is this an integer' part of the
> >initSimpleType function, I am NOT trying to maintain strict XML
> >support. This code is for a project that hides the fact that there
> >even IS XML involved from the user.
> >
> >I will be making all of my source available soon, but as we are
> >working with sensitive data from a number of West African countries
> >I need to be very, very sure that anything I post is 'clean'. Not
> >that I think my code is all that great or anything :~)
> >
> >===============================>
> >  protected void init(SchemaTools sTools) {
> >   this.elementDecl = sTools.getXSElement(element);
> >   XSTypeDefinition typeDef = (XSTypeDefinition)
> >elementDecl.getTypeDefinition();
> >   if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
> >     XSParticle particle = sTools.getXSParticle(elementDecl);
> >     if (particle != null) {
> >      this.minOccurs = particle.getMinOccurs();
> >      this.maxOccurs = particle.getMaxOccurs();
> >      this.unbounded = !particle.getMaxOccursUnbounded();
> >      this.name = element.getNodeName();
> >      this.namespace = element.getNamespaceURI();
> >      this.path = ElementTools.getSchemaPath(element, sTools);
> >      if (typeDef.getBaseType() != null &&
> >         typeDef.getBaseType().getTypeCategory() ==
> >XSTypeDefinition.SIMPLE_TYPE) {
> >        initSimpleType(typeDef.getBaseType());
> >      }
> >
> >     }
> >     else {
> >      throw new NullPointerException("Null particle on
> >element: " + element.getNodeName());
> >     }
> >   }
> >   else { // simple type
> >     initSimpleType(typeDef);
> >   }
> >
> >   }
> >
> >
> >   protected void initSimpleType(XSTypeDefinition typeDef) {
> >   this.simpleType = (XSSimpleType) typeDef;
> >   this.boundedValue = simpleType.getBounded();
> >   this.numeric = simpleType.getNumeric();
> >   this.facets = simpleType.getFacets();
> >   this.primativeType = simpleType.getPrimitiveKind();
> >
> >   for (int i = 0; i < facets.getLength(); i++) {
> >     XSFacet facet = (XSFacet) facets.item(i);
> >     String fValue = facet.getLexicalFacetValue();
> >     short kind = facet.getFacetKind();
> >     // I also care about finding if the primative type is an integer:
> >     if (kind == XSSimpleType.FACET_FRACTIONDIGITS) {
> >      if (this.primativeType ==
> >simpleType.PRIMITIVE_DECIMAL) { // could be an integer
> >        int val = Integer.parseInt(fValue);
> >        if (val == 0) {
> >         this.primativeType = INTEGER;
> >         this.integer = true;
> >        }
> >      }
> >     }
> >     else if (kind == XSSimpleType.FACET_MAXEXCLUSIVE) {
> >      this.maxExclusive = true;
> >      this.maxValue = Double.parseDouble(fValue);
> >     }
> >     else if (kind == XSSimpleType.FACET_MAXINCLUSIVE) {
> >      this.maxInclusive = true;
> >      this.maxValue = Double.parseDouble(fValue);
> >     }
> >     else if (kind == XSSimpleType.FACET_MINEXCLUSIVE) {
> >      this.minExclusive = true;
> >      this.minValue = Double.parseDouble(fValue);
> >     }
> >     else if (kind == XSSimpleType.FACET_MININCLUSIVE) {
> >      this.minInclusive = true;
> >      this.minValue = Double.parseDouble(fValue);
> >     }
> >     else if (kind == XSSimpleType.FACET_MAXLENGTH) {
> >      this.maxLength = Integer.parseInt(fValue);
> >      this.lengthConstrained = true;
> >     }
> >     else if (kind == XSSimpleType.FACET_MINLENGTH) {
> >      this.minLength = Integer.parseInt(fValue);
> >      this.lengthConstrained = true;
> >     }
> >     else if (kind == XSSimpleType.FACET_LENGTH) {
> >      this.minLength = Integer.parseInt(fValue);
> >      this.maxLength = this.minLength;
> >      this.lengthConstrained = true;
> >     }
> >
> >   }
> >
> >   }
> >
> >=============================>
> >
> >Cheers,
> >--
> >Geoff Granum
> >granum@purdue.edu
> >Aeronautical & Astronautical Engineering,
> >Purdue University
> >West Lafayette, Indiana
> >
> >On Mon, 15 Mar 2004 13:53:04 -0600, Henry Miller <hm...@eti.com>
wrote:
> >
> >>Another one from the "yet another newbie question" department...
> >>
> >>I'm trying to preparse XML schema files and I've hit a snag that I
> >>just cannot figure out on my own.
> >>
> >>Using Xerces-J, I'm able to get all the information out, except the
> >>element's data type. In fact, all I can get is the element name and
> >>nothing else.
> >>
> >>Given the following XSD snippet:
> >>
> >>      <element name="PriceRequest">
> >>          <complexType>
> >>              <all>
> >>                  <element name="Symbol" type="string"/>
> >>                  <element name="price" type="float"/>
> >>              </all>
> >>           </complexType>
> >>      </element>
> >>
> >>I managed to drill down through the Xerces-J methods and end up in
> >>the XSComplexTypeDecl class when I hit the problem. My code is
> >>complicated (made worse by my toying with it now), but hopefully
> >>the question is simple enough to answer: How can I get the data
> >>types out of the declared elements (as shown above) from the object
> >>context created by XSComplexTypeDecl? what method(s) do I need to
> >>connect together in order to extract it? Is there a 'set' list?
> >>
> >>I guess that's three questions. I'm so lost... :-)
> >>
> >>I'm able to get the element names from a particle list by parsing a
> >>string that returns all of them using getParticle() in
> >>XSComplexTypeDecl -- probably not the cleanest, but it works. Why
> >>doesn't XSComplexTypeDecl provide types here as well? I'm sure
> >>there's a reason which I don't yet see.
> >>
> >>I'm not even sure what is relevant code to clip out for your
> >>viewing pleasure.
> >>
> >>Any ideas?
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> >For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Preparsing XML Schema data types in Xerces-J

Posted by Henry Miller <hm...@eti.com>.
The good news is -- I figured out my problem. The bad news is -- I 
didn't use the code snippet. Many apologies, but thank you very much 
for the assistance.

After analyzing Elena's response more closely, I saw that I only 
needed to make one more leap from what I already had. Thank you Elena 
for the final clue!

I was already iterating down the "all" particles list, soooo....

It turns out I needed to make the following changes in my code:

    XSObject partObj = particles.getParticles().item(idx);      // 
Clue connected
    XSParticleDecl partObj2 = (XSParticleDecl)partObj;          // me to..
    XSElementDecl partTerm = (XSElementDecl)partObj2.getTerm(); // ..here.

    String dataType = partTerm.getTypeDefinition().toString();  // Elena's note
    StringTokenizer dataTypeST =
                        new StringTokenizer(dataType, ",", false);
    String Trash = dataTypeST.nextToken();
    dataType = dasTypeST.nextToken();

Which gives me exactly "float" or "string" or whatever in my dataType field!

Now, you experts are probably doubling over with laughter at my code, 
but right now I think it's simply beautiful!!!  Another headache 
gone...

Sorry I used internal classes. It's too much code to go back and redo 
now anyway.

--Henry

>Okay, I'm pasting this code snippit with two hopes: One, that it is 
>useful to the poster of the question, and two, that someone can give 
>me a textual 'slap' if the code is 'bad form', or if there are 
>better faster ways to do what I did below. The purpose of the class 
>as a whole is to get some info that I need so that I can get the 
>Grammers out of memory.
>
>To Henry, good luck, to everyone else, thanks :~)
>
>:Note_1: SchemaTools is my own little tool. All you need to care 
>about here is that it DOES return the correct XSElementDecl for 
>whatever element is passed. If there is a better way than holding on 
>to the grammers to do this I'd love to know. My memory footprint is 
>like 50MB. But that is a question for another day (like tomorrow :~)
>
>:Note_2:Regarding the 'is this an integer' part of the 
>initSimpleType function, I am NOT trying to maintain strict XML 
>support. This code is for a project that hides the fact that there 
>even IS XML involved from the user.
>
>I will be making all of my source available soon, but as we are 
>working with sensitive data from a number of West African countries 
>I need to be very, very sure that anything I post is 'clean'. Not 
>that I think my code is all that great or anything :~)
>
>===============================>
>  protected void init(SchemaTools sTools) {
>	this.elementDecl = sTools.getXSElement(element);
>	XSTypeDefinition typeDef = (XSTypeDefinition) 
>elementDecl.getTypeDefinition();
>	if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
>	  XSParticle particle = sTools.getXSParticle(elementDecl);
>	  if (particle != null) {
>		this.minOccurs = particle.getMinOccurs();
>		this.maxOccurs = particle.getMaxOccurs();
>		this.unbounded = !particle.getMaxOccursUnbounded();
>		this.name = element.getNodeName();
>		this.namespace = element.getNamespaceURI();
>		this.path = ElementTools.getSchemaPath(element, sTools);
>		if (typeDef.getBaseType() != null &&
>			typeDef.getBaseType().getTypeCategory() == 
>XSTypeDefinition.SIMPLE_TYPE) {
>		  initSimpleType(typeDef.getBaseType());
>		}
>
>	  }
>	  else {
>		throw new NullPointerException("Null particle on 
>element: " + element.getNodeName());
>	  }
>	}
>	else { // simple type
>	  initSimpleType(typeDef);
>	}
>
>   }
>
>
>   protected void initSimpleType(XSTypeDefinition typeDef) {
>	this.simpleType = (XSSimpleType) typeDef;
>	this.boundedValue = simpleType.getBounded();
>	this.numeric = simpleType.getNumeric();
>	this.facets = simpleType.getFacets();
>	this.primativeType = simpleType.getPrimitiveKind();
>
>	for (int i = 0; i < facets.getLength(); i++) {
>	  XSFacet facet = (XSFacet) facets.item(i);
>	  String fValue = facet.getLexicalFacetValue();
>	  short kind = facet.getFacetKind();
>	  // I also care about finding if the primative type is an integer:
>	  if (kind == XSSimpleType.FACET_FRACTIONDIGITS) {
>		if (this.primativeType == 
>simpleType.PRIMITIVE_DECIMAL) { // could be an integer
>		  int val = Integer.parseInt(fValue);
>		  if (val == 0) {
>			this.primativeType = INTEGER;
>			this.integer = true;
>		  }
>		}
>	  }
>	  else if (kind == XSSimpleType.FACET_MAXEXCLUSIVE) {
>		this.maxExclusive = true;
>		this.maxValue = Double.parseDouble(fValue);
>	  }
>	  else if (kind == XSSimpleType.FACET_MAXINCLUSIVE) {
>		this.maxInclusive = true;
>		this.maxValue = Double.parseDouble(fValue);
>	  }
>	  else if (kind == XSSimpleType.FACET_MINEXCLUSIVE) {
>		this.minExclusive = true;
>		this.minValue = Double.parseDouble(fValue);
>	  }
>	  else if (kind == XSSimpleType.FACET_MININCLUSIVE) {
>		this.minInclusive = true;
>		this.minValue = Double.parseDouble(fValue);
>	  }
>	  else if (kind == XSSimpleType.FACET_MAXLENGTH) {
>		this.maxLength = Integer.parseInt(fValue);
>		this.lengthConstrained = true;
>	  }
>	  else if (kind == XSSimpleType.FACET_MINLENGTH) {
>		this.minLength = Integer.parseInt(fValue);
>		this.lengthConstrained = true;
>	  }
>	  else if (kind == XSSimpleType.FACET_LENGTH) {
>		this.minLength = Integer.parseInt(fValue);
>		this.maxLength = this.minLength;
>		this.lengthConstrained = true;
>	  }
>
>	}
>
>   }
>
>=============================>
>
>Cheers,
>--
>Geoff Granum
>granum@purdue.edu
>Aeronautical & Astronautical Engineering,
>Purdue University
>West Lafayette, Indiana
>
>On Mon, 15 Mar 2004 13:53:04 -0600, Henry Miller <hm...@eti.com> wrote:
>
>>Another one from the "yet another newbie question" department...
>>
>>I'm trying to preparse XML schema files and I've hit a snag that I 
>>just cannot figure out on my own.
>>
>>Using Xerces-J, I'm able to get all the information out, except the 
>>element's data type. In fact, all I can get is the element name and 
>>nothing else.
>>
>>Given the following XSD snippet:
>>
>>      <element name="PriceRequest">
>>          <complexType>
>>              <all>
>>                  <element name="Symbol" type="string"/>
>>                  <element name="price" type="float"/>
>>              </all>
>>           </complexType>
>>      </element>
>>
>>I managed to drill down through the Xerces-J methods and end up in 
>>the XSComplexTypeDecl class when I hit the problem. My code is 
>>complicated (made worse by my toying with it now), but hopefully 
>>the question is simple enough to answer: How can I get the data 
>>types out of the declared elements (as shown above) from the object 
>>context created by XSComplexTypeDecl? what method(s) do I need to 
>>connect together in order to extract it? Is there a 'set' list?
>>
>>I guess that's three questions. I'm so lost... :-)
>>
>>I'm able to get the element names from a particle list by parsing a 
>>string that returns all of them using getParticle() in 
>>XSComplexTypeDecl -- probably not the cleanest, but it works. Why 
>>doesn't XSComplexTypeDecl provide types here as well? I'm sure 
>>there's a reason which I don't yet see.
>>
>>I'm not even sure what is relevant code to clip out for your 
>>viewing pleasure.
>>
>>Any ideas?
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Preparsing XML Schema data types in Xerces-J

Posted by Geoff Granum <gr...@purdue.edu>.
Okay, I'm pasting this code snippit with two hopes: One, that it is useful 
to the poster of the question, and two, that someone can give me a textual 
'slap' if the code is 'bad form', or if there are better faster ways to do 
what I did below. The purpose of the class as a whole is to get some info 
that I need so that I can get the Grammers out of memory.

To Henry, good luck, to everyone else, thanks :~)

:Note_1: SchemaTools is my own little tool. All you need to care about 
here is that it DOES return the correct XSElementDecl for whatever element 
is passed. If there is a better way than holding on to the grammers to do 
this I'd love to know. My memory footprint is like 50MB. But that is a 
question for another day (like tomorrow :~)

:Note_2:Regarding the 'is this an integer' part of the initSimpleType 
function, I am NOT trying to maintain strict XML support. This code is for 
a project that hides the fact that there even IS XML involved from the 
user.

I will be making all of my source available soon, but as we are working 
with sensitive data from a number of West African countries I need to be 
very, very sure that anything I post is 'clean'. Not that I think my code 
is all that great or anything :~)

===============================>
  protected void init(SchemaTools sTools) {
	this.elementDecl = sTools.getXSElement(element);
	XSTypeDefinition typeDef = (XSTypeDefinition) 
elementDecl.getTypeDefinition();
	if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
	  XSParticle particle = sTools.getXSParticle(elementDecl);
	  if (particle != null) {
		this.minOccurs = particle.getMinOccurs();
		this.maxOccurs = particle.getMaxOccurs();
		this.unbounded = !particle.getMaxOccursUnbounded();
		this.name = element.getNodeName();
		this.namespace = element.getNamespaceURI();
		this.path = ElementTools.getSchemaPath(element, sTools);
		if (typeDef.getBaseType() != null &&
			typeDef.getBaseType().getTypeCategory() == 
XSTypeDefinition.SIMPLE_TYPE) {
		  initSimpleType(typeDef.getBaseType());
		}

	  }
	  else {
		throw new NullPointerException("Null particle on element: " 
+ element.getNodeName());
	  }
	}
	else { // simple type
	  initSimpleType(typeDef);
	}

   }


   protected void initSimpleType(XSTypeDefinition typeDef) {
	this.simpleType = (XSSimpleType) typeDef;
	this.boundedValue = simpleType.getBounded();
	this.numeric = simpleType.getNumeric();
	this.facets = simpleType.getFacets();
	this.primativeType = simpleType.getPrimitiveKind();

	for (int i = 0; i < facets.getLength(); i++) {
	  XSFacet facet = (XSFacet) facets.item(i);
	  String fValue = facet.getLexicalFacetValue();
	  short kind = facet.getFacetKind();
	  // I also care about finding if the primative type is an integer:
	  if (kind == XSSimpleType.FACET_FRACTIONDIGITS) {
		if (this.primativeType == simpleType.PRIMITIVE_DECIMAL) { // could be an 
integer
		  int val = Integer.parseInt(fValue);
		  if (val == 0) {
			this.primativeType = INTEGER;
			this.integer = true;
		  }
		}
	  }
	  else if (kind == XSSimpleType.FACET_MAXEXCLUSIVE) {
		this.maxExclusive = true;
		this.maxValue = Double.parseDouble(fValue);
	  }
	  else if (kind == XSSimpleType.FACET_MAXINCLUSIVE) {
		this.maxInclusive = true;
		this.maxValue = Double.parseDouble(fValue);
	  }
	  else if (kind == XSSimpleType.FACET_MINEXCLUSIVE) {
		this.minExclusive = true;
		this.minValue = Double.parseDouble(fValue);
	  }
	  else if (kind == XSSimpleType.FACET_MININCLUSIVE) {
		this.minInclusive = true;
		this.minValue = Double.parseDouble(fValue);
	  }
	  else if (kind == XSSimpleType.FACET_MAXLENGTH) {
		this.maxLength = Integer.parseInt(fValue);
		this.lengthConstrained = true;
	  }
	  else if (kind == XSSimpleType.FACET_MINLENGTH) {
		this.minLength = Integer.parseInt(fValue);
		this.lengthConstrained = true;
	  }
	  else if (kind == XSSimpleType.FACET_LENGTH) {
		this.minLength = Integer.parseInt(fValue);
		this.maxLength = this.minLength;
		this.lengthConstrained = true;
	  }

	}

   }

=============================>

Cheers,
-- 
Geoff Granum
granum@purdue.edu
Aeronautical & Astronautical Engineering,
Purdue University
West Lafayette, Indiana

On Mon, 15 Mar 2004 13:53:04 -0600, Henry Miller <hm...@eti.com> wrote:

> Another one from the "yet another newbie question" department...
>
> I'm trying to preparse XML schema files and I've hit a snag that I just 
> cannot figure out on my own.
>
> Using Xerces-J, I'm able to get all the information out, except the 
> element's data type. In fact, all I can get is the element name and 
> nothing else.
>
> Given the following XSD snippet:
>
>      <element name="PriceRequest">
>          <complexType>
>              <all>
>                  <element name="Symbol" type="string"/>
>                  <element name="price" type="float"/>
>              </all>
>           </complexType>
>      </element>
>
> I managed to drill down through the Xerces-J methods and end up in the 
> XSComplexTypeDecl class when I hit the problem. My code is complicated 
> (made worse by my toying with it now), but hopefully the question is 
> simple enough to answer: How can I get the data types out of the 
> declared elements (as shown above) from the object context created by 
> XSComplexTypeDecl? what method(s) do I need to connect together in order 
> to extract it? Is there a 'set' list?
>
> I guess that's three questions. I'm so lost... :-)
>
> I'm able to get the element names from a particle list by parsing a 
> string that returns all of them using getParticle() in XSComplexTypeDecl 
> -- probably not the cleanest, but it works. Why doesn't 
> XSComplexTypeDecl provide types here as well? I'm sure there's a reason 
> which I don't yet see.
>
> I'm not even sure what is relevant code to clip out for your viewing 
> pleasure.
>
> Any ideas?


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Preparsing XML Schema data types in Xerces-J

Posted by Henry Miller <hm...@eti.com>.
Thank you very much!

I'll go do some more "homework" and try this.

Implementing PSVI's seem daunting to me right now -- I'll first need 
to get over that, I suppose. :-)

Thanks again!

--Henry

>Hi Henry,
>
>First of all, you should not use any Xerces internal classes to query
>schema components.
>
>Instead, use the XML Schema API [1] that allows you to access the PSVI
>including the XML Schema components, e.g. complex types. The interfaces
>defined in the API are isomorphic to the XML Schema components, for example
>the XSComplexTypeDefinition corresponds to the complex type definition
>schema component [2]. In general, for each property defined for an XML
>Schema component there is a corresponding method(s) available, i.e. the
>{content type} for complex type definition corresponds to the following
>methods:
>public short getContentType();
>public XSParticle getParticle();
>public XSSimpleTypeDefinition getSimpleType()
>
>
>>  How can I get the data types out
>>  of the declared elements (as shown above) from the object context
>>  created by XSComplexTypeDecl? what method(s) do I need to connect
>>  together in order to extract it?
>
>First use getParticle() to retrieve the "all" particle, then iterate the
>particles items which are element declarations. From element declaration
>you can retrieve type using getTypeDefinition() method.
>
>
>[1] http://xml.apache.org/xerces2-j/faq-xs.html#faq-3
>[2]
>http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#Complex_Type_Definition_details
>
>Thanks,
>--
>Elena Litani / IBM Toronto
>
>Henry Miller <hm...@eti.com> wrote on 03/15/2004 02:53:04 PM:
>
>>  Another one from the "yet another newbie question" department...
>>
>>  I'm trying to preparse XML schema files and I've hit a snag that I
>>  just cannot figure out on my own.
>>
>>  Using Xerces-J, I'm able to get all the information out, except the
>>  element's data type. In fact, all I can get is the element name and
>>  nothing else.
>>
>>  Given the following XSD snippet:
>>
>>       <element name="PriceRequest">
>>           <complexType>
>>               <all>
>>                   <element name="Symbol" type="string"/>
>>                   <element name="price" type="float"/>
>>               </all>
>>            </complexType>
>>       </element>
>>
>>  I managed to drill down through the Xerces-J methods and end up in
>>  the XSComplexTypeDecl class when I hit the problem. My code is
>>  complicated (made worse by my toying with it now), but hopefully the
>>  question is simple enough to answer: How can I get the data types out
>>  of the declared elements (as shown above) from the object context
>>  created by XSComplexTypeDecl? what method(s) do I need to connect
>>  together in order to extract it? Is there a 'set' list?
>>
>>  I guess that's three questions. I'm so lost... :-)
>>
>>  I'm able to get the element names from a particle list by parsing a
>>  string that returns all of them using getParticle() in
>>  XSComplexTypeDecl -- probably not the cleanest, but it works. Why
>>  doesn't XSComplexTypeDecl provide types here as well? I'm sure
>>  there's a reason which I don't yet see.
>>
>>  I'm not even sure what is relevant code to clip out for your
>viewingpleasure.
>>
>>  Any ideas?
>>  --
>>
>>
>>  --Henry
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>>  For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org


-- 


--Henry


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Preparsing XML Schema data types in Xerces-J

Posted by Elena Litani <el...@ca.ibm.com>.



Hi Henry,

First of all, you should not use any Xerces internal classes to query
schema components.

Instead, use the XML Schema API [1] that allows you to access the PSVI
including the XML Schema components, e.g. complex types. The interfaces
defined in the API are isomorphic to the XML Schema components, for example
the XSComplexTypeDefinition corresponds to the complex type definition
schema component [2]. In general, for each property defined for an XML
Schema component there is a corresponding method(s) available, i.e. the
{content type} for complex type definition corresponds to the following
methods:
public short getContentType();
public XSParticle getParticle();
public XSSimpleTypeDefinition getSimpleType()


> How can I get the data types out
> of the declared elements (as shown above) from the object context
> created by XSComplexTypeDecl? what method(s) do I need to connect
> together in order to extract it?

First use getParticle() to retrieve the "all" particle, then iterate the
particles items which are element declarations. From element declaration
you can retrieve type using getTypeDefinition() method.


[1] http://xml.apache.org/xerces2-j/faq-xs.html#faq-3
[2]
http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#Complex_Type_Definition_details

Thanks,
--
Elena Litani / IBM Toronto

Henry Miller <hm...@eti.com> wrote on 03/15/2004 02:53:04 PM:

> Another one from the "yet another newbie question" department...
>
> I'm trying to preparse XML schema files and I've hit a snag that I
> just cannot figure out on my own.
>
> Using Xerces-J, I'm able to get all the information out, except the
> element's data type. In fact, all I can get is the element name and
> nothing else.
>
> Given the following XSD snippet:
>
>      <element name="PriceRequest">
>          <complexType>
>              <all>
>                  <element name="Symbol" type="string"/>
>                  <element name="price" type="float"/>
>              </all>
>           </complexType>
>      </element>
>
> I managed to drill down through the Xerces-J methods and end up in
> the XSComplexTypeDecl class when I hit the problem. My code is
> complicated (made worse by my toying with it now), but hopefully the
> question is simple enough to answer: How can I get the data types out
> of the declared elements (as shown above) from the object context
> created by XSComplexTypeDecl? what method(s) do I need to connect
> together in order to extract it? Is there a 'set' list?
>
> I guess that's three questions. I'm so lost... :-)
>
> I'm able to get the element names from a particle list by parsing a
> string that returns all of them using getParticle() in
> XSComplexTypeDecl -- probably not the cleanest, but it works. Why
> doesn't XSComplexTypeDecl provide types here as well? I'm sure
> there's a reason which I don't yet see.
>
> I'm not even sure what is relevant code to clip out for your
viewingpleasure.
>
> Any ideas?
> --
>
>
> --Henry
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org