protected Element processElement(XmlCursor xc, String comment,
Inst2XsdOptions options, TypeSystemHolder typeSystemHolder)
{
assert xc.isStart();
Element element = new Element();
element.setName(xc.getName());
element.setGlobal(false);
Type elemType = Type.createUnnamedType(Type.SIMPLE_TYPE_SIMPLE_CONTENT); //assume simple, set later
element.setType(elemType);
StringBuffer textBuff = new StringBuffer();
StringBuffer commentBuff = new StringBuffer();
List children = new ArrayList();
List attributes = new ArrayList();
loop: do
{
XmlCursor.TokenType tt = xc.toNextToken();
switch (tt.intValue())
{
case XmlCursor.TokenType.INT_ATTR:
// todo check for xsi:type
// ignore xsi:... attributes other than xsi:nil
QName attName = xc.getName();
if (!_xsiNil.getNamespaceURI().equals(attName.getNamespaceURI()))
attributes.add(processAttribute(xc, options, element.getName().getNamespaceURI(), typeSystemHolder));
else if (_xsiNil.equals(attName))
element.setNillable(true);
break;
case XmlCursor.TokenType.INT_START:
children.add(processElement(xc, commentBuff.toString(), options, typeSystemHolder));
commentBuff.delete(0, commentBuff.length());
break;
case XmlCursor.TokenType.INT_TEXT:
textBuff.append(xc.getChars());
break;
case XmlCursor.TokenType.INT_COMMENT:
commentBuff.append(xc.getTextValue());
break;
case XmlCursor.TokenType.INT_NAMESPACE:
// ignore,
// each element and attribute will take care to define itself in the right targetNamespace
break;
case XmlCursor.TokenType.INT_END:
break loop;
case XmlCursor.TokenType.INT_PROCINST:
// ignore
break;
case XmlCursor.TokenType.INT_ENDDOC:
break loop;
case XmlCursor.TokenType.INT_NONE:
break loop;
case XmlCursor.TokenType.INT_STARTDOC:
throw new IllegalStateException();
default:
throw new IllegalStateException("Unknown TokenType.");
}
}
while( true );
String collapsedText = XmlWhitespace.collapse(textBuff.toString(), XmlWhitespace.WS_COLLAPSE);
String commnetStr = (comment == null ?
( commentBuff.length() == 0 ? null : commentBuff.toString() ) :
( commentBuff.length() == 0 ? comment : commentBuff.insert(0, comment).toString()) );
element.setComment(commnetStr);
if (children.size()>0)
{
// complex content
if (collapsedText.length()>0)
{
elemType.setContentType(Type.COMPLEX_TYPE_MIXED_CONTENT);
}
else
{
elemType.setContentType(Type.COMPLEX_TYPE_COMPLEX_CONTENT);
}
processElementsInComplexType(elemType, children, element.getName().getNamespaceURI(), typeSystemHolder, options);
processAttributesInComplexType(elemType, attributes);
}
else
{
// simple content