bool Module::WriteStaticXML (const string& xml_file) { DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(StrX("Core").XMLchar() ); if (impl==NULL) return false; DOMDocument* doc = impl->createDocument( 0, StrX("PARAM").XMLchar(), 0); DOMNode* topnode = doc->getFirstChild(); Parameters* parameters = m_seq_tree->GetParameters(); DOMNode* backup_node = parameters->GetNode(); XMLIO* xmlio = new XMLIO(); parameters->SetNode(topnode); parameters->AddAllDOMattributes(false); if ( ((DOMElement*) topnode)->getAttributeNode(StrX("Name").XMLchar()) != NULL) ((DOMElement*) topnode)->removeAttribute (StrX("Name").XMLchar()); parameters->SetNode(backup_node); //recursively add elements if (!StaticDOM(doc,topnode)) return false; xmlio->Write (impl, topnode, xml_file); delete doc; delete topnode; delete parameters; delete backup_node; delete xmlio; return true; }
// --------------------------------------------------------------------------- // This method assumes that currentNode is an xinclude element and parses // it accordingly, acting on what it finds. // --------------------------------------------------------------------------- bool XIncludeUtils::doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){ bool modifiedNode = false; /* the relevant attributes to look for */ const XMLCh *href = NULL; const XMLCh *parse = NULL; const XMLCh *xpointer = NULL; const XMLCh *encoding = NULL; const XMLCh *accept = NULL; const XMLCh *acceptlanguage = NULL; DOMNode *includeParent = xincludeNode->getParentNode(); if(xincludeNode->hasAttributes()) { /* get all the attributes of the node */ DOMNamedNodeMap *pAttributes = xincludeNode->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); const XMLCh *attrName = pAttributeNode->getName(); /* check each attribute against the potential useful names */ if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeHREFAttrName)){ href = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeParseAttrName)){ parse = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeXPointerAttrName)){ xpointer = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeEncodingAttrName)){ encoding = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptAttrName)){ accept = pAttributeNode->getValue(); } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptLanguageAttrName)){ acceptlanguage = pAttributeNode->getValue(); } else { /* if any other attribute is in the xi namespace, it's an error */ const XMLCh *attrNamespaceURI = pAttributeNode->getNamespaceURI(); if (attrNamespaceURI && XMLString::equals(attrNamespaceURI, XIncludeUtils::fgXIIIncludeNamespaceURI)){ } else { /* ignore - any other attribute is allowed according to spec, and must be ignored */ } } } } // 3.1 xi:include Element // The children property of the xi:include element may include a single xi:fallback element; // the appearance of more than one xi:fallback element, an xi:include element, // or any other element from the XInclude namespace is a fatal error. DOMNode *child; DOMElement *fallback = NULL; for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){ if(child->getNodeType()!=DOMNode::ELEMENT_NODE) continue; if ( isXIFallbackDOMNode(child) ){ if (fallback != NULL){ /* fatal error - there are more than one fallback children */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeMultipleFallbackElems, parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI()); return false; } fallback = (DOMElement*)child; } else if(isXIIncludeDOMNode(child) || XMLString::equals(child->getNamespaceURI(), XIncludeUtils::fgXIIIncludeNamespaceURI)) { /* fatal error - an xi element different from xi:fallback is a child of xi:include */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeDisallowedChild, child->getNodeName(), parsedDocument->getDocumentURI()); return false; } } if (href == NULL){ /* this is an unrecoverable error until we have xpointer support - if there is an xpointer, the current document is assumed however, there is no xpointer support yet */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeNoHref, NULL, parsedDocument->getDocumentURI()); return false; } /* set up the accept and accept-language values */ if (accept != NULL){ } if (parse == NULL){ /* use the default, as specified */ parse = XIncludeUtils::fgXIIncludeParseAttrXMLValue; } if (xpointer != NULL){ /* not supported yet */ /* Note that finding an xpointer attr along with parse="text" is a Fatal Error * - http://www.w3.org/TR/xinclude/#include-location */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeXPointerNotSupported, NULL, href); return false; } /* set up the href according to what has gone before */ XIncludeLocation hrefLoc(href); XIncludeLocation relativeLocation(href); const XMLCh *includeBase = xincludeNode->getBaseURI(); if (includeBase != NULL){ hrefLoc.prependPath(includeBase); } if (getBaseAttrValue(xincludeNode) != NULL){ relativeLocation.prependPath(getBaseAttrValue(xincludeNode)); } /* Take the relevant action - we need to retrieve the target as a whole before we can know if it was successful or not, therefore the do* methods do not modify the parsedDocument. Swapping the results in is left to the caller (i.e. here) */ DOMText *includedText = NULL; DOMDocument *includedDoc = NULL; if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrXMLValue)){ /* including a XML element */ includedDoc = doXIncludeXMLFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), xincludeNode, parsedDocument, entityResolver); } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){ /* including a text value */ includedText = doXIncludeTEXTFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), encoding, xincludeNode, parsedDocument, entityResolver); } else { /* invalid parse attribute value - fatal error according to the specification */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeInvalidParseVal, parse, parsedDocument->getDocumentURI()); return false; } RefVectorOf<DOMNode> delayedProcessing(12,false); if (includedDoc == NULL && includedText == NULL){ /* there was an error - this is now a resource error let's see if there is a fallback */ XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedResourceError, hrefLoc.getLocation(), parsedDocument->getDocumentURI()); if (includeParent == NULL){ includeParent = parsedDocument; } // we could be getting errors trying to insert elements at the root of the document, so we should use replaceChild; // in order to handle multiple nodes, add them to a document fragment and use that to replace the original node if (fallback){ /* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */ XMLUri parentURI(includeParent->getBaseURI()); XMLUri includedURI(fallback->getBaseURI()); if (fallback->hasChildNodes()){ DOMDocumentFragment* frag = parsedDocument->createDocumentFragment(); DOMNode *child = fallback->getFirstChild(); /* add the content of the fallback element, and remove the fallback elem itself */ for ( ; child != NULL ; child=child->getNextSibling()){ if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){ continue; } DOMNode *newNode = parsedDocument->importNode(child, true); /* if the paths differ we need to add a base attribute */ if (newNode->getNodeType()==DOMNode::ELEMENT_NODE && !XMLString::equals(parentURI.getPath(), includedURI.getPath())){ if (getBaseAttrValue(newNode) == NULL){ /* need to calculate the proper path difference to get the relativePath */ ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, getBaseAttrValue(fallback->getParentNode())); } else { /* the included node has base of its own which takes precedence */ XIncludeLocation xil(getBaseAttrValue(newNode)); if (getBaseAttrValue(fallback->getParentNode()) != NULL){ /* prepend any specific base modification of the xinclude node */ xil.prependPath(getBaseAttrValue(fallback->getParentNode())); } ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, xil.getLocation()); } } DOMNode *newChild = frag->appendChild(newNode); // don't process the node now, wait until it is placed in the final position delayedProcessing.addElement(newChild); //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver); } includeParent->replaceChild(frag, xincludeNode); frag->release(); for(XMLSize_t i=0;i<delayedProcessing.size();i++) { DOMNode* childNode=delayedProcessing.elementAt(i); parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver); } modifiedNode = true; } else { /* empty fallback element - simply remove it! */ includeParent->removeChild(xincludeNode); modifiedNode = true; } } else { XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedNoFallback, parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI()); return false; } } else { if (includedDoc){ /* record the successful include while we process the children */ addDocumentURIToCurrentInclusionHistoryStack(hrefLoc.getLocation()); DOMDocumentFragment* frag = parsedDocument->createDocumentFragment(); /* need to import the document prolog here */ DOMNode *child = includedDoc->getFirstChild(); for (; child != NULL; child = child->getNextSibling()) { if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE) continue; // check for NOTATION or ENTITY clash if(child->getNodeType()==DOMNode::ELEMENT_NODE && includedDoc->getDoctype()!=NULL) { DOMNamedNodeMap *pAttributes = child->getAttributes(); XMLSize_t nSize = pAttributes->getLength(); for(XMLSize_t i=0;i<nSize;++i) { DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i); const DOMTypeInfo * typeInfo=pAttributeNode->getSchemaTypeInfo(); if(typeInfo && XMLString::equals(typeInfo->getTypeNamespace(), XMLUni::fgInfosetURIName)) { if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgNotationString)) { const XMLCh* notationName=pAttributeNode->getNodeValue(); DOMNotation* notat=(DOMNotation*)includedDoc->getDoctype()->getNotations()->getNamedItem(notationName); // ensure we have a DTD if(parsedDocument->getDoctype()==NULL) parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild()); DOMNotation* myNotation=(DOMNotation*)parsedDocument->getDoctype()->getNotations()->getNamedItem(notationName); if(myNotation==NULL) { // it's missing, add it parsedDocument->getDoctype()->getNotations()->setNamedItem(parsedDocument->importNode(notat, true)); } else if(XMLString::equals(myNotation->getPublicId(), notat->getPublicId()) && XMLString::equals(myNotation->getSystemId(), notat->getSystemId()) && XMLString::equals(myNotation->getBaseURI(), notat->getBaseURI())) { // it's duplicate, ignore it } else { // it's a conflict, report it XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingNotation, notationName, parsedDocument->getDocumentURI()); } } else if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgEntityString)) { const XMLCh* entityName=pAttributeNode->getNodeValue(); DOMEntity* ent=(DOMEntity*)includedDoc->getDoctype()->getEntities()->getNamedItem(entityName); // ensure we have a DTD if(parsedDocument->getDoctype()==NULL) parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild()); DOMEntity* myEnt=(DOMEntity*)parsedDocument->getDoctype()->getEntities()->getNamedItem(entityName); if(myEnt==NULL) { // it's missing, add it parsedDocument->getDoctype()->getEntities()->setNamedItem(parsedDocument->importNode(ent, true)); } else if(XMLString::equals(myEnt->getPublicId(), ent->getPublicId()) && XMLString::equals(myEnt->getSystemId(), ent->getSystemId()) && XMLString::equals(myEnt->getBaseURI(), ent->getBaseURI())) { // it's duplicate, ignore it } else { // it's a conflict, report it XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingEntity, entityName, parsedDocument->getDocumentURI()); } } } } } DOMNode *newNode = parsedDocument->importNode(child, true); DOMNode *newChild = frag->appendChild(newNode); // don't process the node now, wait until it is placed in the final position delayedProcessing.addElement(newChild); //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver); } includeParent->replaceChild(frag, xincludeNode); frag->release(); for(XMLSize_t i=0;i<delayedProcessing.size();i++) { DOMNode* childNode=delayedProcessing.elementAt(i); parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver); } popFromCurrentInclusionHistoryStack(NULL); modifiedNode = true; } else if (includedText){ includeParent->replaceChild(includedText, xincludeNode); modifiedNode = true; } } if (includedDoc) includedDoc->release(); return modifiedNode; }
int main() { try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char *pMessage = XMLString::transcode(toCatch.getMessage()); fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n" " Message is: %s\n", pMessage); XMLString::release(&pMessage); return -1; } // Create a XMLCh buffer for string manipulation XMLCh tempStr[4000]; XMLCh featureStr[100]; XMLString::transcode("Traversal",featureStr,99); // // Doc - Create a small document tree // { //creating a DOM Tree /* Tests are based on the tree structure below doc - root - E11 (attr01) - textNode1 - E111 - E112 - cdataSec - E12 (attr02) - textNode2 - E121 - E122 - E13 - E131 - docPI - comment */ DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(featureStr); DOMDocument* doc = impl->createDocument(); //Creating a root element XMLString::transcode("RootElement", tempStr, 3999); DOMElement* root = doc->createElement(tempStr); doc->appendChild(root); //Creating the siblings of root XMLString::transcode("FirstSibling", tempStr, 3999); DOMElement* E11 = doc->createElement(tempStr); root->appendChild(E11); XMLString::transcode("SecondSibling", tempStr, 3999); DOMElement* E12 = doc->createElement(tempStr); root->appendChild(E12); XMLString::transcode("ThirdSibling", tempStr, 3999); DOMElement* E13 = doc->createElement(tempStr); root->appendChild(E13); //Attaching texts to few siblings XMLString::transcode("Text1", tempStr, 3999); DOMText* textNode1 = doc->createTextNode(tempStr); E11->appendChild(textNode1); XMLString::transcode("Text2", tempStr, 3999); DOMText* textNode2 = doc->createTextNode(tempStr); E12->appendChild(textNode2); //creating child of siblings XMLString::transcode("FirstSiblingChild1", tempStr, 3999); DOMElement* E111 = doc->createElement(tempStr); E11->appendChild(E111); XMLString::transcode("Attr01", tempStr, 3999); DOMAttr* attr01 = doc->createAttribute(tempStr); DOMNode* rem = E11->setAttributeNode(attr01); if (rem) rem->release(); XMLString::transcode("FirstSiblingChild2", tempStr, 3999); DOMElement* E112 = doc->createElement(tempStr); E11->appendChild(E112); XMLString::transcode("SecondSiblingChild1", tempStr, 3999); DOMElement* E121 = doc->createElement(tempStr); E12->appendChild(E121); XMLString::transcode("Attr01", tempStr, 3999); DOMAttr* attr02 = doc->createAttribute(tempStr); rem = E12->setAttributeNode(attr02); if (rem) rem->release(); XMLString::transcode("SecondSiblingChild2", tempStr, 3999); DOMElement* E122 = doc->createElement(tempStr); E12->appendChild(E122); XMLString::transcode("ThirdSiblingChild1", tempStr, 3999); DOMElement* E131 = doc->createElement(tempStr); E13->appendChild(E131); XMLString::transcode("DocComment", tempStr, 3999); DOMComment* comment = doc->createComment(tempStr); root->appendChild(comment); XMLString::transcode("DocCDataSection", tempStr, 3999); DOMCDATASection* cdataSec = doc->createCDATASection(tempStr); E11->appendChild(cdataSec); XMLString::transcode("DocPI", tempStr, 3999); XMLCh piStr[] = {chLatin_D, chLatin_o, chLatin_c, chLatin_P, chLatin_I, chNull}; DOMProcessingInstruction* docPI = doc->createProcessingInstruction(piStr, tempStr); E13->appendChild(docPI); /* following are whatToShow types: SHOW_ALL = 0x0000FFFF, SHOW_ELEMENT = 0x00000001, SHOW_ATTRIBUTE = 0x00000002, SHOW_TEXT = 0x00000004, SHOW_CDATA_SECTION = 0x00000008, SHOW_ENTITY_REFERENCE = 0x00000010, SHOW_ENTITY = 0x00000020, SHOW_PROCESSING_INSTRUCTION = 0x00000040, SHOW_COMMENT = 0x00000080, SHOW_DOCUMENT = 0x00000100, SHOW_DOCUMENT_TYPE = 0x00000200, SHOW_DOCUMENT_FRAGMENT = 0x00000400, SHOW_NOTATION = 0x00000800 */ ////////// NodeIterator Test Cases //////////////// { // all node iterating test DOMNode* node = doc->getFirstChild(); UNUSED(node); // silence warning unsigned long whatToShow = DOMNodeFilter::SHOW_ALL; MyFilter* filter = new MyFilter(0); DOMNodeIterator* iter = ((DOMDocumentTraversal*)doc)->createNodeIterator(root, whatToShow, filter, true); TASSERT(iter->getWhatToShow() == 65535); TASSERT(iter->getExpandEntityReferences() == 1); DOMNode* nd; nd = iter->nextNode(); TASSERT (nd ==root); nd = iter->nextNode(); TASSERT (nd ==E11); nd = iter->nextNode(); TASSERT(nd == textNode1); nd = iter->nextNode(); TASSERT(nd == E111); nd = iter->nextNode(); TASSERT(nd == E112); nd = iter->nextNode(); TASSERT(nd == cdataSec); nd = iter->nextNode(); TASSERT(nd == E12); nd = iter->nextNode(); TASSERT(nd == textNode2); nd = iter->nextNode(); TASSERT(nd == E121); nd = iter->nextNode(); TASSERT(nd == E122); nd = iter->nextNode(); TASSERT(nd == E13); nd = iter->nextNode(); TASSERT(nd == E131); nd = iter->nextNode(); TASSERT(nd == docPI); nd = iter->nextNode(); TASSERT(nd == comment); nd = iter->previousNode(); TASSERT(nd == comment); nd = iter->previousNode(); TASSERT(nd == docPI); nd = iter->previousNode(); TASSERT(nd == E131); //test getRoot TASSERT(iter->getRoot() == root); TASSERT(iter->getRoot() != doc); delete filter; } { //element node iterating test DOMNode* node = doc->getFirstChild(); UNUSED(node); // silence warning unsigned long whatToShow = DOMNodeFilter::SHOW_ELEMENT; MyFilter* filter = new MyFilter(DOMNode::ELEMENT_NODE); DOMNodeIterator* iter = doc->createNodeIterator(root, whatToShow, filter, true); TASSERT(iter->getWhatToShow() == 1); TASSERT(iter->getExpandEntityReferences() == 1); DOMNode* nd; nd = iter->nextNode(); TASSERT (nd ==root); nd = iter->nextNode(); TASSERT (nd ==E11); nd = iter->nextNode(); TASSERT(nd == E111); nd = iter->nextNode(); TASSERT(nd == E112); nd = iter->nextNode(); TASSERT(nd == E12); nd = iter->nextNode(); TASSERT(nd == E121); nd = iter->nextNode(); TASSERT(nd == E122); nd = iter->nextNode(); TASSERT(nd == E13); nd = iter->nextNode(); TASSERT(nd == E131); nd = iter->previousNode(); TASSERT(nd == E131); nd = iter->previousNode(); TASSERT(nd == E13); nd = iter->previousNode(); TASSERT(nd == E122); delete filter; } { // Text node iterating test DOMNode* node = doc->getFirstChild(); UNUSED(node); // silence warning unsigned long whatToShow = DOMNodeFilter::SHOW_TEXT; MyFilter* filter = new MyFilter(DOMNode::TEXT_NODE); DOMNodeIterator* iter = ((DOMDocumentTraversal*)doc)->createNodeIterator(root, whatToShow, filter, true); TASSERT(iter->getWhatToShow() == 4); TASSERT(iter->getExpandEntityReferences() == 1); DOMNode* nd; nd = iter->nextNode(); TASSERT (nd ==textNode1); nd = iter->nextNode(); TASSERT (nd ==textNode2); nd = iter->previousNode(); TASSERT(nd == textNode2); delete filter; } { //CDataSection node itearating test DOMNode* node = doc->getFirstChild(); UNUSED(node); // silence warning unsigned long whatToShow = DOMNodeFilter::SHOW_CDATA_SECTION; MyFilter* filter = new MyFilter(DOMNode::CDATA_SECTION_NODE); DOMNodeIterator* iter = doc->createNodeIterator(root, whatToShow, filter, true); TASSERT(iter->getWhatToShow() == 8); TASSERT(iter->getExpandEntityReferences() == 1); DOMNode* nd; nd = iter->nextNode(); TASSERT(nd == cdataSec); nd = iter->nextNode(); TASSERT(nd == 0); delete filter; } { // PI nodes iterating test DOMNode* node = doc->getFirstChild(); UNUSED(node); // silence warning unsigned long whatToShow = DOMNodeFilter::SHOW_PROCESSING_INSTRUCTION; MyFilter* filter = new MyFilter(DOMNode::PROCESSING_INSTRUCTION_NODE); DOMNodeIterator* iter = ((DOMDocumentTraversal*)doc)->createNodeIterator(root, whatToShow, filter, true); TASSERT(iter->getWhatToShow() == 64); TASSERT(iter->getExpandEntityReferences() == 1); DOMNode* nd; nd = iter->nextNode(); TASSERT(nd == docPI); nd = iter->nextNode(); TASSERT(nd == 0); delete filter; } { DOMNode* node = doc->getFirstChild(); UNUSED(node); // silence warning unsigned long whatToShow = DOMNodeFilter::SHOW_COMMENT; MyFilter* filter = new MyFilter(DOMNode::COMMENT_NODE); DOMNodeIterator* iter = doc->createNodeIterator(root, whatToShow, filter, true); TASSERT(iter->getWhatToShow() == 128); TASSERT(iter->getExpandEntityReferences() == 1); DOMNode* nd; nd = iter->nextNode(); TASSERT(nd == comment); nd = iter->nextNode(); TASSERT(nd == 0); delete filter; } ////////// TreeWalker Test Cases //////////////// { unsigned long whatToShow = DOMNodeFilter::SHOW_ALL; DOMTreeWalker* tw = ((DOMDocumentTraversal*)doc)->createTreeWalker(doc, whatToShow, 0, true); TASSERT(tw->getCurrentNode() == doc); TASSERT(tw->firstChild() == root); TASSERT(tw->nextSibling() == 0); TASSERT(tw->lastChild() == comment); TASSERT(tw->firstChild() == 0); TASSERT(tw->lastChild() == 0); TASSERT(tw->nextSibling() == 0); TASSERT(tw->nextNode() == 0); TASSERT(tw->previousSibling() == E13); TASSERT(tw->previousNode() == E122); TASSERT(tw->parentNode() == E12); TASSERT(tw->firstChild() == textNode2); TASSERT(tw->previousSibling() == 0); TASSERT(tw->nextSibling() == E121); TASSERT(tw->nextNode() == E122); TASSERT(tw->parentNode() == E12); TASSERT(tw->previousSibling() == E11); TASSERT(tw->previousNode() == root); TASSERT(tw->previousNode() == doc); TASSERT(tw->previousNode() == 0); TASSERT(tw->parentNode() == 0); TASSERT(tw->getCurrentNode() == doc); } { MyFilter mf(DOMNode::ELEMENT_NODE); unsigned long whatToShow = DOMNodeFilter::SHOW_ALL; DOMTreeWalker* tw = doc->createTreeWalker(root, whatToShow, &mf, true); TASSERT(tw->getCurrentNode() == root); TASSERT(tw->parentNode() == 0); //should not change currentNode TASSERT(tw->getCurrentNode() == root); TASSERT(tw->nextNode() == E11); TASSERT(tw->nextNode() == E111); tw->setCurrentNode(E12); //when first is not visible, should it go to its sibling? TASSERT(tw->firstChild() == E121); //first visible child TASSERT(tw->previousSibling() == 0); } { MyFilter mf(DOMNode::ELEMENT_NODE, true); unsigned long whatToShow = DOMNodeFilter::SHOW_ELEMENT; DOMTreeWalker* tw = ((DOMDocumentTraversal*)doc)->createTreeWalker(root, whatToShow, &mf, true); tw->setCurrentNode(E12); TASSERT(tw->firstChild() == E121); //still first visible child } { MyFilter mf(DOMNode::TEXT_NODE); unsigned long whatToShow = DOMNodeFilter::SHOW_TEXT; DOMTreeWalker* tw = doc->createTreeWalker(root, whatToShow, &mf, true); //when first is not visible, should it go to its descendent? TASSERT(tw->firstChild() == textNode1); //E11 skipped TASSERT(tw->firstChild() == 0); TASSERT(tw->nextNode() == textNode2); TASSERT(tw->nextSibling() == 0); TASSERT(tw->parentNode() == 0); //no visible ancestor TASSERT(tw->getCurrentNode() == textNode2); tw->setCurrentNode(root); //when last is not visible, should it go to its sibling & descendent? TASSERT(tw->lastChild() == textNode2); //last visible child tw->setCurrentNode(E12); //when next sibling is not visible, should it go to its descendent? TASSERT(tw->nextSibling() == 0); } { MyFilter mf(DOMNode::TEXT_NODE, true); unsigned long whatToShow = DOMNodeFilter::SHOW_TEXT; DOMTreeWalker* tw = ((DOMDocumentTraversal*)doc)->createTreeWalker(root, whatToShow, &mf, true); TASSERT(tw->firstChild() == 0); //E11 rejected and no children is TEXT TASSERT(tw->getCurrentNode() == root); TASSERT(tw->nextNode() == 0); //E11 rejected so can't get to textNode1 //test getRoot TASSERT(tw->getRoot() == root); TASSERT(tw->getRoot() != doc); } doc->release(); }; // And call the termination method XMLPlatformUtils::Terminate(); if (errorOccurred) { printf("Test Failed\n"); return 4; } printf("Test Run Successfully\n"); return 0; };