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 Mark Brucks <br...@j3s.us> on 2003/08/19 18:39:40 UTC

existence of 'ref' attribute, value constraints

There seems to be no way within the API to determine if the 'ref' 
attribute exists on an <attribute> element information item.  This is 
important, because the value constraints are absent on the Attribute 
Declaration Schema Component when the 'ref' attribute is absent (they 
must come from the Attribute Use Schema Component).  Actually, I guess 
the problem is really that  when the 'ref' attribute exists, there are 
two sets of value constraints, one from the Attribute Use Schema 
Component and one from the global Attribute Declaration Schema Component 
(for the referenced attribute).  Are these the same value constraints, 
and if so why are they duplicated?  My confusion stems from section 
3.2.2 of XML Schema Part 1.

On a somewhat related note, how do you determine if the value of the 
'use' attribute is 'optional' vs. 'prohibited'?  There is the 
"getRequired()" method on XSAttributeUse, but that method returns false 
if either the use attribute is absent or it's value is not 'required'. 
 As such, there is no way using the interface API definitions to 
distinguish between the values of 'optional' and 'prohibited'.  Of 
course, since the fUse member of XSAttributeUseImpl is public, I can 
look at it, but I'd rather have a way through one of the public methods 
of XSAttributeUse.

Thanks - Mark Brucks



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


Is it possible to have a ModelGroup as a child of ModelGroup??

Posted by Geoff Granum <gr...@purdue.edu>.
I'm writing a bit of recursive code (which has most assuredly been written 
by dozens before I), and I am wondering if there will ever be a case such 
that a model group could ever be a direct child of a model group? I don't 
believe that this would happen, but would like to be sure.

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");
/*@todo 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
granum@purdue.edu
Aeronautical & Astronautical Engineering,
Purdue University
West Lafayette, Indiana

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