// --------------------------------------------------------------------------- // XSDDOMParser: Implementation of the XMLDocumentHandler interface // --------------------------------------------------------------------------- void XSDDOMParser::startElement( const XMLElementDecl& elemDecl , const unsigned int urlId , const XMLCh* const elemPrefix , const RefVectorOf<XMLAttr>& attrList , const unsigned int attrCount , const bool isEmpty , const bool isRoot) { fDepth++; // while it is true that non-whitespace character data // may only occur in appInfo or documentation // elements, it's certainly legal for comments and PI's to // occur as children of annotation; we need // to account for these here. if (fAnnotationDepth == -1) { if (XMLString::equals(elemDecl.getBaseName(), SchemaSymbols::fgELT_ANNOTATION) && XMLString::equals(getURIText(urlId), SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) { fAnnotationDepth = fDepth; startAnnotation(elemDecl, attrList, attrCount); } } else if (fDepth == fAnnotationDepth+1) { fInnerAnnotationDepth = fDepth; startAnnotationElement(elemDecl, attrList, attrCount); } else { startAnnotationElement(elemDecl, attrList, attrCount); // avoid falling through; don't call startElement in this case return; } DOMElement *elem; if (urlId != fScanner->getEmptyNamespaceId()) //TagName has a prefix { if (elemPrefix && *elemPrefix) { XMLBufBid elemQName(&fBufMgr); elemQName.set(elemPrefix); elemQName.append(chColon); elemQName.append(elemDecl.getBaseName()); elem = createElementNSNode( fScanner->getURIText(urlId), elemQName.getRawBuffer()); } else { elem = createElementNSNode( fScanner->getURIText(urlId), elemDecl.getBaseName()); } } else { elem = createElementNSNode(0, elemDecl.getBaseName()); } DOMElementImpl *elemImpl = (DOMElementImpl *) elem; for (unsigned int index = 0; index < attrCount; ++index) { const XMLAttr* oneAttrib = attrList.elementAt(index); unsigned int attrURIId = oneAttrib->getURIId(); const XMLCh* namespaceURI = 0; //for xmlns=... if (XMLString::equals(oneAttrib->getName(), XMLUni::fgXMLNSString)) attrURIId = fScanner->getXMLNSNamespaceId(); //TagName has a prefix if (attrURIId != fScanner->getEmptyNamespaceId()) namespaceURI = fScanner->getURIText(attrURIId); //get namespaceURI // revisit. Optimize to init the named node map to the // right size up front. DOMAttrImpl *attr = (DOMAttrImpl *) fDocument->createAttributeNS(namespaceURI, oneAttrib->getQName()); attr->setValue(oneAttrib -> getValue()); DOMNode* remAttr = elemImpl->setAttributeNodeNS(attr); if (remAttr) remAttr->release(); // Attributes of type ID. If this is one, add it to the hashtable of IDs // that is constructed for use by GetElementByID(). if (oneAttrib->getType()==XMLAttDef::ID) { if (fDocument->fNodeIDMap == 0) fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument); fDocument->fNodeIDMap->add(attr); attr->fNode.isIdAttr(true); } attr->setSpecified(oneAttrib->getSpecified()); } // set up the default attributes if (elemDecl.hasAttDefs()) { XMLAttDefList* defAttrs = &elemDecl.getAttDefList(); XMLAttDef* attr = 0; DOMAttrImpl * insertAttr = 0; while (defAttrs->hasMoreElements()) { attr = &defAttrs->nextElement(); const XMLAttDef::DefAttTypes defType = attr->getDefaultType(); if ((defType == XMLAttDef::Default) || (defType == XMLAttDef::Fixed)) { // DOM Level 2 wants all namespace declaration attributes // to be bound to "http://www.w3.org/2000/xmlns/" // So as long as the XML parser doesn't do it, it needs to // done here. const XMLCh* qualifiedName = attr->getFullName(); XMLBufBid bbPrefixQName(&fBufMgr); XMLBuffer& prefixBuf = bbPrefixQName.getBuffer(); int colonPos = -1; unsigned int uriId = fScanner->resolveQName(qualifiedName, prefixBuf, ElemStack::Mode_Attribute, colonPos); const XMLCh* namespaceURI = 0; if (XMLString::equals(qualifiedName, XMLUni::fgXMLNSString)) uriId = fScanner->getXMLNSNamespaceId(); //TagName has a prefix if (uriId != fScanner->getEmptyNamespaceId()) namespaceURI = fScanner->getURIText(uriId); insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS( namespaceURI, qualifiedName); DOMAttr* remAttr = elemImpl->setDefaultAttributeNodeNS(insertAttr); if (remAttr) remAttr->release(); if (attr->getValue() != 0) { insertAttr->setValue(attr->getValue()); insertAttr->setSpecified(false); } } insertAttr = 0; attr->reset(); } } fCurrentParent->appendChild(elem); fNodeStack->push(fCurrentParent); fCurrentParent = elem; fCurrentNode = elem; fWithinElement = true; // If an empty element, do end right now (no endElement() will be called) if (isEmpty) endElement(elemDecl, urlId, isRoot, elemPrefix); }
void XPathMatcher::startElement(const XMLElementDecl& elemDecl, const unsigned int urlId, const XMLCh* const elemPrefix, const RefVectorOf<XMLAttr>& attrList, const unsigned int attrCount) { for (int i = 0; i < (int) fLocationPathSize; i++) { // push context int startStep = fCurrentStep[i]; fStepIndexes->elementAt(i)->push(startStep); // try next xpath, if not matching if ((fMatched[i] & XP_MATCHED_D) == XP_MATCHED || fNoMatchDepth[i] > 0) { fNoMatchDepth[i]++; continue; } if((fMatched[i] & XP_MATCHED_D) == XP_MATCHED_D) { fMatched[i] = XP_MATCHED_DP; } // consume self::node() steps XercesLocationPath* locPath = fLocationPaths->elementAt(i); int stepSize = locPath->getStepSize(); while (fCurrentStep[i] < stepSize && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::SELF) { fCurrentStep[i]++; } if (fCurrentStep[i] == stepSize) { fMatched[i] = XP_MATCHED; continue; } // now if the current step is a descendant step, we let the next // step do its thing; if it fails, we reset ourselves // to look at this step for next time we're called. // so first consume all descendants: int descendantStep = fCurrentStep[i]; while (fCurrentStep[i] < stepSize && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::DESCENDANT) { fCurrentStep[i]++; } bool sawDescendant = fCurrentStep[i] > descendantStep; if (fCurrentStep[i] == stepSize) { fNoMatchDepth[i]++; continue; } // match child::... step, if haven't consumed any self::node() if ((fCurrentStep[i] == startStep || fCurrentStep[i] > descendantStep) && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::CHILD) { XercesStep* step = locPath->getStep(fCurrentStep[i]); XercesNodeTest* nodeTest = step->getNodeTest(); if (nodeTest->getType() == XercesNodeTest::QNAME) { QName elemQName(elemPrefix, elemDecl.getElementName()->getLocalPart(), urlId, fMemoryManager); // if (!(*(nodeTest->getName()) == *(elemDecl.getElementName()))) { if (!(*(nodeTest->getName()) == elemQName)) { if(fCurrentStep[i] > descendantStep) { fCurrentStep[i] = descendantStep; continue; } fNoMatchDepth[i]++; continue; } } fCurrentStep[i]++; } if (fCurrentStep[i] == stepSize) { if (sawDescendant) { fCurrentStep[i] = descendantStep; fMatched[i] = XP_MATCHED_D; } else { fMatched[i] = XP_MATCHED; } continue; } // match attribute::... step if (fCurrentStep[i] < stepSize && locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::ATTRIBUTE) { if (attrCount) { XercesNodeTest* nodeTest = locPath->getStep(fCurrentStep[i])->getNodeTest(); for (unsigned int attrIndex = 0; attrIndex < attrCount; attrIndex++) { const XMLAttr* curDef = attrList.elementAt(attrIndex); if (nodeTest->getType() != XercesNodeTest::QNAME || (*(nodeTest->getName()) == *(curDef->getAttName()))) { fCurrentStep[i]++; if (fCurrentStep[i] == stepSize) { fMatched[i] = XP_MATCHED_A; int j=0; for(; j<i && ((fMatched[j] & XP_MATCHED) != XP_MATCHED); j++) ; if(j == i) { SchemaAttDef* attDef = ((SchemaElementDecl&) elemDecl).getAttDef(curDef->getName(), curDef->getURIId()); DatatypeValidator* dv = (attDef) ? attDef->getDatatypeValidator() : 0; matched(curDef->getValue(), dv, false); } } break; } } } if ((fMatched[i] & XP_MATCHED) != XP_MATCHED) { if(fCurrentStep[i] > descendantStep) { fCurrentStep[i] = descendantStep; continue; } fNoMatchDepth[i]++; } } } }