Essentially I need to be sure that when my function calls itself from the model group block, it cannot go straight back into the model group block again -- this would 'flatten' the tree, if it didn't crash outright. Here is the code, just for kicks:
Alternativly, if there is some utility class that already does this that I just haven't found, I'd love to hear about it :~)
This code, obviously, does not work yet. It DOES work for much of what I need it for (normal elements). I don't implement wildcards becuase:
a.) I don't know quite how. Do you just ignore the children when validating?
b.) I don't ever create XML schema with no-type empty elements; hence no wildcards in my schema ( I think)
I have it working a different way currently, but am working on making it easier to read and faster. Two things I'm not too great at :~)
Thanks!
/**
* Create a node from an XSObject. Returns <code>parent</code> after attempting to append all nodes from
* <code>obj</code>. This will likely require recurrsive calls to this function. Sets values to their
* defaults, if they are specified in the Schema.
* @param obj The XSObject to append to <code>parent</code> as a Node object.
* @param parent The Node object to append to
* @return <code>parent</code>, after appending <code>obj</code> and all of its children.
*/
public Node getNode(XSObject obj, Node parent) {
short objType = obj.getType();
Node node = null;
if (objType == XSConstants.PARTICLE) {
obj = ( (XSParticleDecl) obj).getTerm(); // Either a XSElementDeclaration, XSModelGroup, or an XSWildcard
objType = obj.getType();
}
if (objType == XSConstants.MODEL_GROUP) {
XSModelGroupImpl grp = (XSModelGroupImpl) obj;
XSObjectList lst = grp.getParticles();
XSParticle part = null;
for (int i = 0; i < lst.getLength(); i++) {
part = (XSParticleDecl) lst.item(i);
parent = getNode(part, parent); // This won't work if Model Groups can have model groups for children!!!!!!!
}
return parent;
}
if (objType == XSConstants.ELEMENT_DECLARATION) {
if ( (node = getNode(obj)) != null) { // The other function, which I need to get rid of. This function and that one rely on each other
parent.appendChild(node);
}
return parent;
}
if (objType == XSConstants.WILDCARD) {
System.out.println("wildcard");
/[EMAIL PROTECTED] Implement wildcard
}
if (objType == XSConstants.TYPE_DEFINITION) { System.out.println("type def"); XSTypeDefinition type = (XSTypeDefinition) obj; if (type.getTypeCategory() == type.COMPLEX_TYPE) { // handle COMPLEX_TYPE case XSComplexTypeDecl cType = (XSComplexTypeDecl) type; return getNode( (XSParticle) cType.getParticle(), parent); } else if (type.getTypeCategory() == type.SIMPLE_TYPE) { XSSimpleTypeDecl sType = (XSSimpleTypeDecl) obj; Node textNode = document.createTextNode(""); parent.appendChild(textNode); return parent;
}
else {
System.out.println("Error with TYPE_DECLARATION in getNode(XSObject)");
}
} return parent; }
-- Geoff Granum [EMAIL PROTECTED] Aeronautical & Astronautical Engineering, Purdue University West Lafayette, Indiana
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
