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
[EMAIL PROTECTED]
Aeronautical & Astronautical Engineering,
Purdue University
West Lafayette, Indiana

On Mon, 15 Mar 2004 13:53:04 -0600, Henry Miller <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to