/*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      Node newChild;
      NodeList elementList;
      Node employeeNode;
      NodeList childList;
      Node oldChild;
      Node replacedNode;
      doc = (Document) baseT::load("staff", true);
      newChild = doc.getDocumentElement();
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("employee"));
      employeeNode = elementList.item(1);
      childList = employeeNode.getChildNodes();
      oldChild = childList.item(0);
      
      {
         boolean success = false;
         try {
            replacedNode = employeeNode.replaceChild(newChild, oldChild);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::HIERARCHY_REQUEST_ERR);
         }
         assertTrue(success);
      }

   }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node employeeNode;
     NodeList employeeList;
     Node child;
     int length;
     String childName;
     doc = (Document) baseT::load("staff", false);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("employee"));
     employeeNode = elementList.item(2);
     employeeList = employeeNode.getChildNodes();
     length = (int) employeeList.getLength();
     
     if (baseT::equals(6, length)) {
         child = employeeList.item(1);
     } else {
         child = employeeList.item(3);
     }
       
   childName = child.getNodeName();
     baseT::assertEquals("name", childName, __LINE__, __FILE__);
 
  }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList elementList;
      Element firstNode;
      Node testNode;
      NamedNodeMap attributes;
      Attr domesticAttr;
      Attr setAttr;
      Node setNode;
      doc = (Document) baseT::load("staff", true);
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("address"));
      firstNode = (Element) elementList.item(0);
      domesticAttr = doc.createAttribute(SA::construct_from_utf8("domestic"));
      domesticAttr.setValue(SA::construct_from_utf8("Yes"));
      setAttr = firstNode.setAttributeNode(domesticAttr);
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("address"));
      testNode = elementList.item(2);
      attributes = testNode.getAttributes();
      
      {
         boolean success = false;
         try {
            setNode = attributes.setNamedItem(domesticAttr);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::INUSE_ATTRIBUTE_ERR);
         }
         assertTrue(success);
      }

   }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Element lastEmployee;
     NodeList lastempList;
     Node child;
     String childName;
     std::vector<string_type> result;
     
     std::vector<string_type> expectedResult;
     expectedResult.push_back(SA::construct_from_utf8("employeeId"));
     expectedResult.push_back(SA::construct_from_utf8("name"));
     expectedResult.push_back(SA::construct_from_utf8("position"));
     expectedResult.push_back(SA::construct_from_utf8("salary"));
     expectedResult.push_back(SA::construct_from_utf8("gender"));
     expectedResult.push_back(SA::construct_from_utf8("address"));
     
     doc = (Document) baseT::load("staff", false);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("employee"));
     lastEmployee = (Element) elementList.item(4);
     lastempList = lastEmployee.getElementsByTagName(SA::construct_from_utf8("*"));
     for (unsigned int indexN65642 = 0; indexN65642 != lastempList.getLength(); indexN65642++) {
         child = (Node) lastempList.item(indexN65642);
   childName = child.getNodeName();
     result.push_back(childName);
       }
     baseT::assertEquals(expectedResult, result, __LINE__, __FILE__);
 
  }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node employeeNode;
     NodeList childNodes;
     Node childNode;
     int childType;
     String childName;
     std::vector<string_type> elementNames;
     
     std::vector<string_type> expectedElementNames;
     expectedElementNames.push_back(SA::construct_from_utf8("employeeId"));
     expectedElementNames.push_back(SA::construct_from_utf8("name"));
     expectedElementNames.push_back(SA::construct_from_utf8("position"));
     expectedElementNames.push_back(SA::construct_from_utf8("salary"));
     expectedElementNames.push_back(SA::construct_from_utf8("gender"));
     expectedElementNames.push_back(SA::construct_from_utf8("address"));
     
     doc = (Document) baseT::load("staff", false);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("employee"));
     employeeNode = elementList.item(1);
     childNodes = employeeNode.getChildNodes();
     for (unsigned int indexN65644 = 0; indexN65644 != childNodes.getLength(); indexN65644++) {
         childNode = (Node) childNodes.item(indexN65644);
   childType = (int) childNode.getNodeType();
     
     if (baseT::equals(1, childType)) {
         childName = childNode.getNodeName();
     elementNames.push_back(childName);
     }
     }
     baseT::assertEquals(expectedElementNames, elementNames, __LINE__, __FILE__);
 
  }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node employeeNode;
     NodeList childList;
     Node oldChild;
     Node removedChild;
     String childName;
     int length;
     doc = (Document) baseT::load("staff", true);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("employee"));
     employeeNode = elementList.item(1);
     childList = employeeNode.getChildNodes();
     length = (int) childList.getLength();
     oldChild = childList.item(0);
     removedChild = employeeNode.removeChild(oldChild);
     childName = removedChild.getNodeName();
     
     if (baseT::equals(6, length)) {
         baseT::assertEquals("employeeId", childName, __LINE__, __FILE__);
 } else {
         baseT::assertEquals("#text", childName, __LINE__, __FILE__);
 }
       
   
  }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     Element root;
     NodeList elementList;
     Element testName;
     Node firstChild;
     String childValue;
     Text textNode;
     Node retNode;
     doc = (Document) baseT::load("hc_staff", true);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("sup"));
     testName = (Element) elementList.item(0);
     textNode = doc.createTextNode(SA::construct_from_utf8(""));
     retNode = testName.appendChild(textNode);
     textNode = doc.createTextNode(SA::construct_from_utf8(",000"));
     retNode = testName.appendChild(textNode);
     root = doc.getDocumentElement();
     root.normalize();
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("sup"));
     testName = (Element) elementList.item(0);
     firstChild = testName.getFirstChild();
     childValue = firstChild.getNodeValue();
     baseT::assertEquals("56,000,000", childValue, __LINE__, __FILE__);
 
  }
Element *Context::getNowEle(Element *pEle, std::string eleName) {
    NodeList *tempNodeList = pEle->getChildNodes();

    for (int i = 0; i < tempNodeList->getLength(); i++) {
        if (dynamic_cast<Element *>(tempNodeList->item(i)) != 0) {
            Element *nowEle = static_cast<Element *>(tempNodeList->item(i));

            if (nowEle->getTagName()->equals(eleName)) {
                return nowEle;
            }
        }
    }

    return 0;
}
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList genderList;
      Node gender;
      NodeList genList;
      Node gen;
      NodeList gList;
      Node g;
      NamedNodeMap attrList;
      Attr attrNode;
      doc = (Document) baseT::load("staff", true);
      genderList = doc.getElementsByTagName(SA::construct_from_utf8("gender"));
      gender = genderList.item(2);
      baseT::assertNotNull(gender, __LINE__, __FILE__);
      genList = gender.getChildNodes();
      gen = genList.item(0);
      baseT::assertNotNull(gen, __LINE__, __FILE__);
      gList = gen.getChildNodes();
      g = gList.item(0);
      baseT::template skipIfNot<EntityReference>(g);
     baseT::assertNotNull(g, __LINE__, __FILE__);
      attrList = g.getAttributes();
      baseT::assertNotNull(attrList, __LINE__, __FILE__);
      attrNode = (Attr) attrList.getNamedItem(SA::construct_from_utf8("domestic"));
      baseT::assertNotNull(attrNode, __LINE__, __FILE__);
      
      {
         boolean success = false;
         try {
            attrNode.setValue(SA::construct_from_utf8("newvalue"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR);
         }
         assertTrue(success);
      }

      {
         boolean success = false;
         try {
            attrNode.setNodeValue(SA::construct_from_utf8("newvalue2"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR);
         }
         assertTrue(success);
      }

   }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     NodeList childList;
     Node childNode;
     Node newChild;
     Node memberNode;
     String memberName;
     std::vector<string_type> refreshedActual;
     
     std::vector<string_type> actual;
     
     int nodeType;
     std::vector<string_type> expected;
     expected.push_back(SA::construct_from_utf8("strong"));
     expected.push_back(SA::construct_from_utf8("code"));
     expected.push_back(SA::construct_from_utf8("sup"));
     expected.push_back(SA::construct_from_utf8("var"));
     expected.push_back(SA::construct_from_utf8("acronym"));
     expected.push_back(SA::construct_from_utf8("em"));
     
     Node appendedChild;
     doc = (Document) baseT::load("hc_staff", true);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("p"));
     childNode = elementList.item(1);
     childList = ((Element) /*Node */childNode).getElementsByTagName(SA::construct_from_utf8("*"));
     newChild = childList.item(0);
     appendedChild = childNode.appendChild(newChild);
     for (unsigned int indexN65669 = 0; indexN65669 != childList.getLength(); indexN65669++) {
         memberNode = (Node) childList.item(indexN65669);
   memberName = memberNode.getNodeName();
     actual.push_back(memberName);
       }
     baseT::assertEquals(expected, actual, __LINE__, __FILE__);
 childList = childNode.getChildNodes();
     for (unsigned int indexN65692 = 0; indexN65692 != childList.getLength(); indexN65692++) {
         memberNode = (Node) childList.item(indexN65692);
   nodeType = (int) memberNode.getNodeType();
     
     if (baseT::equals(1, nodeType)) {
         memberName = memberNode.getNodeName();
     refreshedActual.push_back(memberName);
     }
     }
     baseT::assertEquals(expected, refreshedActual, __LINE__, __FILE__);
 
  }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc1;
      Document doc2;
      Attr newAttribute;
      NodeList addressElementList;
      Element testAddress;
      Attr attrAddress;
      doc1 = (Document) baseT::load("staff", true);
      doc2 = (Document) baseT::load("staff", false);
      newAttribute = doc2.createAttribute(SA::construct_from_utf8("newAttribute"));
      addressElementList = doc1.getElementsByTagName(SA::construct_from_utf8("address"));
      testAddress = (Element) addressElementList.item(4);
      
      {
         boolean success = false;
         try {
            attrAddress = testAddress.setAttributeNode(newAttribute);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR);
         }
         assertTrue(success);
      }

   }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList acronymList;
      Node testNode;
      NamedNodeMap attributes;
      Attr titleAttr;
      String value;
      Node textNode;
      Node retval;
      Node lastChild;
      Document otherDoc;
      doc = (Document) baseT::load("hc_staff", true);
      otherDoc = (Document) baseT::load("hc_staff", true);
      acronymList = doc.getElementsByTagName(SA::construct_from_utf8("acronym"));
      testNode = acronymList.item(3);
      attributes = testNode.getAttributes();
      titleAttr = (Attr) attributes.getNamedItem(SA::construct_from_utf8("title"));
      textNode = otherDoc.createTextNode(SA::construct_from_utf8("terday"));
      
      {
         boolean success = false;
         try {
            retval = titleAttr.appendChild(textNode);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR);
         }
         assertTrue(success);
      }

   }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList genderList;
      Node gender;
      EntityReference entRef;
      Element entElement;
      Node entNode;
      Node appendedChild;
      doc = (Document) baseT::load("staff", true);
      genderList = doc.getElementsByTagName(SA::construct_from_utf8("gender"));
      gender = genderList.item(2);
      entRef = doc.createEntityReference(SA::construct_from_utf8("ent4"));
      baseT::assertNotNull(entRef, __LINE__, __FILE__);
      appendedChild = gender.appendChild(entRef);
      entNode = entRef.getFirstChild();
      baseT::template skipIfNot<Element>(entNode);
     entElement = (Element) entRef.getFirstChild();
      baseT::assertNotNull(entElement, __LINE__, __FILE__);
      
      {
         boolean success = false;
         try {
            entElement.removeAttribute(SA::construct_from_utf8("domestic"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR);
         }
         assertTrue(success);
      }

   }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      Element rootNode;
      Node newChild;
      NodeList elementList;
      Node oldChild;
      Node replacedChild;
      doc = (Document) baseT::load("hc_staff", true);
      newChild = doc.createAttribute(SA::construct_from_utf8("lang"));
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("p"));
      oldChild = elementList.item(1);
      rootNode = (Element) oldChild.getParentNode();
      
      {
         boolean success = false;
         try {
            replacedChild = rootNode.replaceChild(newChild, oldChild);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::HIERARCHY_REQUEST_ERR);
         }
         assertTrue(success);
      }

   }
Beispiel #15
0
void NodeRemovedFromDocument(Node* node)
{
	NodeList* childNodes = node->get_childNodes();

	unsigned int length = childNodes->get_length();

	for (unsigned int i = 0; i < length; ++i)
	{
		Node* child = childNodes->item(i);

		NodeRemovedFromDocument(child);
	}

	Document* ownerDocument = node->get_ownerDocument();

	DocumentEvent* ownerDocumentEvent = dynamic_cast<DocumentEvent*>(ownerDocument);
	ASSERT(ownerDocumentEvent != nullptr);

	MutationEvent* event = dynamic_cast<MutationEvent*>(ownerDocumentEvent->createEvent(S("MutationEvent")));

	event->initMutationEvent(S("DOMNodeRemovedFromDocument"), false, false, NULL/*relatedNode*/, nullptr, nullptr, nullptr, CHANGE_UNKNOWN);

	EventTarget* target = dynamic_cast<EventTarget*>(node);

	target->dispatchEvent(event);
}
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node child;
     String childName;
     String childValue;
     int commentCount = 0;
     int childType;
     NamedNodeMap attributes;
     doc = (Document) baseT::load("hc_staff", false);
     elementList = doc.getChildNodes();
     for (unsigned int indexN65630 = 0; indexN65630 != elementList.getLength(); indexN65630++) {
         child = (Node) elementList.item(indexN65630);
   childType = (int) child.getNodeType();
     
     if (baseT::equals(8, childType)) {
         childName = child.getNodeName();
     baseT::assertEquals("#comment", childName, __LINE__, __FILE__);
 childValue = child.getNodeValue();
     baseT::assertEquals(" This is comment number 1.", childValue, __LINE__, __FILE__);
 attributes = child.getAttributes();
     baseT::assertNull(attributes, __LINE__, __FILE__);
     commentCount += 1;
     }
     }
     assertTrue((commentCount < 2));
     
  }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList elementList;
      Element testEmployee;
      Node firstC;
      String childName;
      int nodeType;
      CharacterData employeeIDNode;
      String employeeID;
      doc = (Document) baseT::load("hc_staff", false);
      elementList = doc.getElementsByTagName(SA::construct_from_utf8("p"));
      testEmployee = (Element) elementList.item(3);
      firstC = testEmployee.getFirstChild();
      nodeType = (int) firstC.getNodeType();
      
    while (baseT::equals(3, nodeType)) {
    firstC = firstC.getNextSibling();
      nodeType = (int) firstC.getNodeType();
      
    }
childName = firstC.getNodeName();
      baseT::assertEquals("em", childName, __LINE__, __FILE__);
  employeeIDNode = (CharacterData) firstC.getFirstChild();
      employeeID = employeeIDNode.getNodeValue();
      baseT::assertEquals("EMP0004", employeeID, __LINE__, __FILE__);
  
   }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node child;
     String childName;
     String childValue;
     int commentCount = 0;
     int childType;
     doc = (Document) baseT::load("staff", false);
     elementList = doc.getChildNodes();
     for (unsigned int indexN65623 = 0; indexN65623 != elementList.getLength(); indexN65623++) {
         child = (Node) elementList.item(indexN65623);
   childType = (int) child.getNodeType();
     
     if (baseT::equals(8, childType)) {
         childName = child.getNodeName();
     baseT::assertEquals("#comment", childName, __LINE__, __FILE__);
 childValue = child.getNodeValue();
     baseT::assertEquals(" This is comment number 1.", childValue, __LINE__, __FILE__);
 commentCount = commentCount + 1;
     }
     }
     baseT::assertEquals(1, commentCount, __LINE__, __FILE__);
 
  }
    /*
     * Runs the test case.
     */
    void runTest()
    {
        Document doc;
        Attr newAttribute;
        NodeList addressElementList;
        Element testAddress;
        Element newElement;
        Attr attrAddress;
        Node appendedChild;
        Attr setAttr1;
        Attr setAttr2;
        doc = (Document) baseT::load("hc_staff", true);
        addressElementList = doc.getElementsByTagName(SA::construct_from_utf8("body"));
        testAddress = (Element) addressElementList.item(0);
        newElement = doc.createElement(SA::construct_from_utf8("p"));
        appendedChild = testAddress.appendChild(newElement);
        newAttribute = doc.createAttribute(SA::construct_from_utf8("title"));
        setAttr1 = newElement.setAttributeNode(newAttribute);

        {
            boolean success = false;
            try {
                setAttr2 = testAddress.setAttributeNode(newAttribute);
            } catch (const DOMException& ex) {
                success = (ex.code() == DOMException::INUSE_ATTRIBUTE_ERR);
            }
            assertTrue(success);
        }

    }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc1;
      Document doc2;
      NodeList elementList;
      Node testAddress;
      NamedNodeMap attributes;
      Node newAttribute;
      String strong;
      Node setNode;
      doc1 = (Document) baseT::load("hc_staff", true);
      doc2 = (Document) baseT::load("hc_staff", true);
      elementList = doc1.getElementsByTagName(SA::construct_from_utf8("acronym"));
      testAddress = elementList.item(2);
      newAttribute = doc2.createAttribute(SA::construct_from_utf8("newAttribute"));
      attributes = testAddress.getAttributes();
      
      {
         boolean success = false;
         try {
            setNode = attributes.setNamedItem(newAttribute);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR);
         }
         assertTrue(success);
      }

   }
Beispiel #21
0
static Position innerNodePosition(const Position& innerPosition)
{
    ASSERT(!innerPosition.isBeforeAnchor());
    ASSERT(!innerPosition.isAfterAnchor());
    HTMLElement* element = toHTMLElement(innerPosition.anchorNode());
    ASSERT(element);
    NodeList* childNodes = element->childNodes();
    if (!childNodes->length())
        return Position(element, 0);

    unsigned offset = 0;

    if (innerPosition.isOffsetInAnchor())
        offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), static_cast<int>(childNodes->length())));
    else if (innerPosition.isAfterChildren())
        offset = childNodes->length();

    if (offset == childNodes->length())
        return Position(element->lastChild(), PositionAnchorType::AfterAnchor);

    Node* node = childNodes->item(offset);
    if (node->isTextNode())
        return Position(toText(node), 0);

    return Position(node, PositionAnchorType::BeforeAnchor);
}
Beispiel #22
0
NodeList
Element::getElementsByTagName (const DOMString& name)
{
    NodeList elements;
    
    for (size_t i = 0; i < _children.length(); i++) {
        Node* node = _children.item(i);

        if (node->nodeType() == Node::ELEMENT_NODE) {
            if (((Element*)node)->tagName() == Utils::toUpper(name)) {
                elements.insert(node);
            }
        }
    }

    for (size_t i = 0; i < _children.length(); i++) {
        Node* node = _children.item(i);

        if (node->nodeType() == Node::ELEMENT_NODE) {
            NodeList subElements = ((Element*)node)->getElementsByTagName(name);

            for (size_t h = 0; h < subElements.length(); h++) {
                elements.insert(subElements.item(h));
            }
        }
    }

    return elements;
}
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc1;
      Document doc2;
      Node refChild;
      Node newChild;
      NodeList elementList;
      Node elementNode;
      Node insertedNode;
      doc1 = (Document) baseT::load("staff", false);
      doc2 = (Document) baseT::load("staff", true);
      newChild = doc1.createElement(SA::construct_from_utf8("newChild"));
      elementList = doc2.getElementsByTagName(SA::construct_from_utf8("employee"));
      elementNode = elementList.item(1);
      refChild = elementNode.getFirstChild();
      
      {
         boolean success = false;
         try {
            insertedNode = elementNode.insertBefore(newChild, refChild);
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR);
         }
         assertTrue(success);
      }

   }
void ReadAppXml::read(std::string filePathName) throw(Exception) {
    Document *doc = 0;
    //建立一个解析器工厂
    DocumentBuilderFactory *factory = DocumentBuilderFactory::newInstance();
    //获得一个DocumentBuilder对象,这个对象代表了具体的DOM解析器
    DocumentBuilder *builder = factory->newDocumentBuilder();
    //得到一个表示XML文档的Document对象
    doc = builder->parse(filePathName);
    //去掉XML文档中作为格式化内容的空白而映射在DOM树中的不必要的Text Node对象
    doc->normalize();

    //      //获取jdbc
    //      NodeList jdbc = doc.getElementsByTagName("jdbc");
    //      //只有一个jdbc,获取jdbc中的驱动类的名称
    //      NodeList driverClassNode = ((Element)jdbc.item(0)).getElementsByTagName("driver-class");
    //      String driverClass = driverClassNode.item(0).getFirstChild().getNodeValue();
    //      System.out.println("driverClass=="+driverClass);
    //      //同理获取url、user、password等值
    //      NodeList urlNode = ((Element)jdbc.item(0)).getElementsByTagName("url");
    //      String url = urlNode.item(0).getFirstChild().getNodeValue();
    //      System.out.println("url=="+url);
    //
    //      NodeList userNode = ((Element)jdbc.item(0)).getElementsByTagName("user");
    //      String user = userNode.item(0).getFirstChild().getNodeValue();
    //      System.out.println("user=="+user);
    //
    //      NodeList passwordNode = ((Element)jdbc.item(0)).getElementsByTagName("password");
    //      String password = passwordNode.item(0).getFirstChild().getNodeValue();
    //      System.out.println("password=="+password);
    //      //获取application-xml
    //      NodeList applicationXmlNode = doc.getElementsByTagName("application-xml");
    //      String applicationXml = applicationXmlNode.item(0).getFirstChild().getNodeValue();
    //      System.out.println("applicationXml=="+applicationXml);

    //先要获取spring-default,然后获取application-xmls
    //然后才能获取application-xml
    NodeList *springDefaultNode = doc->getElementsByTagName("spring-default");
    NodeList *appXmlsNode = (static_cast<Element *>(springDefaultNode->item(0)))->getElementsByTagName("application-xmls");
    NodeList *appXmlNode = (static_cast<Element *>(appXmlsNode->item(0)))->getElementsByTagName("application-xml");

    //循环获取每个application-xml元素的值
    for (int i = 0; i < appXmlNode->getLength(); i++) {
        std::string applicationXml = appXmlNode->item(i)->getFirstChild()->getNodeValue();
        puts("applicationXml==" + applicationXml);
    }
}
Beispiel #25
0
// Compiles a list of zoomable subtargets.
void compileZoomableSubtargets(const NodeList& intersectedNodes, SubtargetGeometryList& subtargets)
{
    unsigned length = intersectedNodes.length();
    for (unsigned i = 0; i < length; ++i) {
        Node* const candidate = intersectedNodes.item(i);
        if (nodeIsZoomTarget(candidate))
            appendZoomableSubtargets(candidate, subtargets);
    }
}
Beispiel #26
0
// Compiles a list of subtargets of all the relevant target nodes.
void compileSubtargetList(const NodeList& intersectedNodes, SubtargetGeometryList& subtargets, NodeFilter nodeFilter)
{
    // Find candidates responding to tap gesture events in O(n) time.
    HashMap<Node*, Node*> responderMap;
    HashSet<Node*> ancestorsToRespondersSet;
    Vector<Node*> candidates;

    // A node matching the NodeFilter is called a responder. Candidate nodes must either be a
    // responder or have an ancestor that is a responder.
    // This iteration tests all ancestors at most once by caching earlier results.
    unsigned length = intersectedNodes.length();
    for (unsigned i = 0; i < length; ++i) {
        Node* const node = intersectedNodes.item(i);
        Vector<Node*> visitedNodes;
        Node* respondingNode = 0;
        for (Node* visitedNode = node; visitedNode; visitedNode = visitedNode->parentOrHostNode()) {
            // Check if we already have a result for a common ancestor from another candidate.
            respondingNode = responderMap.get(visitedNode);
            if (respondingNode)
                break;
            visitedNodes.append(visitedNode);
            // Check if the node filter applies, which would mean we have found a responding node.
            if (nodeFilter(visitedNode)) {
                respondingNode = visitedNode;
                // Continue the iteration to collect the ancestors of the responder, which we will need later.
                for (visitedNode = visitedNode->parentOrHostNode(); visitedNode; visitedNode = visitedNode->parentOrHostNode()) {
                    pair<HashSet<Node*>::iterator, bool> addResult = ancestorsToRespondersSet.add(visitedNode);
                    if (!addResult.second)
                        break;
                }
                break;
            }
        }
        // Insert the detected responder for all the visited nodes.
        for (unsigned j = 0; j < visitedNodes.size(); j++)
            responderMap.add(visitedNodes[j], respondingNode);

        if (respondingNode)
            candidates.append(node);
    }

    // We compile the list of component absolute quads instead of using the bounding rect
    // to be able to perform better hit-testing on inline links on line-breaks.
    length = candidates.size();
    for (unsigned i = 0; i < length; i++) {
        Node* candidate = candidates[i];
        // Skip nodes who's responders are ancestors of other responders. This gives preference to
        // the inner-most event-handlers. So that a link is always preferred even when contained
        // in an element that monitors all click-events.
        Node* respondingNode = responderMap.get(candidate);
        ASSERT(respondingNode);
        if (ancestorsToRespondersSet.contains(respondingNode))
            continue;
        appendSubtargetsForNodeToList(candidate, subtargets);
    }
}
 /*
  * Runs the test case.
  */
 void runTest()
 {
    Document doc;
    NodeList elementList;
    Node employeeNode;
    NodeList employeeList;
    Node secondChildNode;
    Node textNode;
    Node noChildNode;
    doc = (Document) baseT::load("staff", false);
    elementList = doc.getElementsByTagName(SA::construct_from_utf8("employee"));
    employeeNode = elementList.item(0);
    employeeList = employeeNode.getChildNodes();
    secondChildNode = employeeList.item(1);
    textNode = secondChildNode.getFirstChild();
    noChildNode = textNode.getFirstChild();
    baseT::assertNull(noChildNode, __LINE__, __FILE__);
    
 }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Element cdataName;
     NodeList childList;
     Node child;
     String cdataNodeValue;
     doc = (Document) baseT::load("staff", false);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("name"));
     cdataName = (Element) elementList.item(1);
     childList = cdataName.getChildNodes();
     child = childList.item(1);
     
     if ((baseT::isNull(child))) {
         child = doc.createCDATASection(SA::construct_from_utf8("This is a CDATASection with EntityReference number 2 &ent2;"));
     }
   cdataNodeValue = child.getNodeValue();
     baseT::assertEquals("This is a CDATASection with EntityReference number 2 &ent2;", cdataNodeValue, __LINE__, __FILE__);
 
  }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Node employeeNode;
     NodeList childList;
     Node refChild;
     Node newChild;
     Node insertedNode;
     String childName;
     doc = (Document) baseT::load("hc_staff", true);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("p"));
     employeeNode = elementList.item(1);
     childList = employeeNode.getChildNodes();
     refChild = childList.item(3);
     newChild = doc.createElement(SA::construct_from_utf8("br"));
     insertedNode = employeeNode.insertBefore(newChild, refChild);
     childName = insertedNode.getNodeName();
     baseT::assertEquals("br", childName, __LINE__, __FILE__);
 
  }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList testList;
     Node piNode;
     String piValue;
     doc = (Document) baseT::load("staff", false);
     testList = doc.getChildNodes();
     piNode = testList.item(0);
     piValue = piNode.getNodeValue();
     baseT::assertEquals("PIDATA", piValue, __LINE__, __FILE__);
 
  }