void Parser::parseCompositor( ParserContext *context, const QDomElement &element, ComplexType &ct ) { QName name = element.tagName(); bool isChoice = name.localName() == "choice"; bool isSequence = name.localName() == "sequence"; Compositor compositor; if ( isChoice ) compositor.setType( Compositor::Choice ); else if ( isSequence ) compositor.setType( Compositor::Sequence ); if ( isChoice || isSequence ) { Element::List newElements; QDomElement childElement = element.firstChildElement(); while ( !childElement.isNull() ) { QName csName = childElement.tagName(); if ( csName.localName() == "element" ) { Element newElement; if ( isChoice ) { newElement = parseElement( context, childElement, ct.nameSpace(), element ); } else { if ( isSequence ) { // occurence attributes can be either in the // parent (sequence) to on the current element if ( childElement.hasAttribute("minOccurs") || childElement.hasAttribute("maxOccurs")) { newElement = parseElement( context, childElement, ct.nameSpace(), childElement ); } else { newElement = parseElement( context, childElement, ct.nameSpace(), element ); } } else { newElement = parseElement( context, childElement, ct.nameSpace(), childElement ); } } newElements.append( newElement ); compositor.addChild( csName ); } else if ( csName.localName() == "any" ) { addAny( context, childElement, ct ); } else if ( isChoice ) { parseCompositor( context, childElement, ct ); } else if ( isSequence ) { parseCompositor( context, childElement, ct ); } childElement = childElement.nextSiblingElement(); } foreach( Element e, newElements ) { e.setCompositor( compositor ); ct.addElement( e ); }
void Parser::parseCompositor( ParserContext *context, const QDomElement &element, ComplexType &ct ) { const QName name( element.tagName() ); bool isChoice = name.localName() == QLatin1String("choice"); bool isSequence = name.localName() == QLatin1String("sequence"); Compositor compositor; if ( isChoice ) compositor.setType( Compositor::Choice ); else if ( isSequence ) compositor.setType( Compositor::Sequence ); compositor.setMaxOccurs( readMaxOccurs( element ) ); if ( isChoice || isSequence ) { Element::List newElements; QDomElement childElement = element.firstChildElement(); while ( !childElement.isNull() ) { NSManager namespaceManager( context, childElement ); const QName csName( childElement.tagName() ); if ( csName.localName() == QLatin1String("element") ) { Element newElement; if ( isChoice ) { newElement = parseElement( context, childElement, ct.nameSpace(), element ); } else { newElement = parseElement( context, childElement, ct.nameSpace(), childElement ); } newElements.append( newElement ); compositor.addChild( csName ); } else if ( csName.localName() == QLatin1String("any") ) { addAny( context, childElement, ct ); } else if ( isChoice ) { parseCompositor( context, childElement, ct ); } else if ( isSequence ) { parseCompositor( context, childElement, ct ); } childElement = childElement.nextSiblingElement(); } foreach( Element e, newElements ) { e.setCompositor( compositor ); ct.addElement( e ); }