/*
   * 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 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__);
 
  }
예제 #3
0
  /*
   * 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__);
 
  }
예제 #4
0
  /*
   * 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__);
 
  }
예제 #5
0
  /*
   * 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;
     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__);
 }
       
   
  }
예제 #7
0
  /*
   * 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__);
 
  }
예제 #8
0
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;
}
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);
    }
}
예제 #10
0
/**
 * Execute a list upon a given node.  For each Axis encountered,
 * get the nodes encountered so far, and execute the rest of the
 * list of tokens upon each of the nodes.
 */
int TokenExecutor::execute(std::vector<Token> &tokens,
                            int position,
                            const NodePtr /*node*/,
                            NodeList &result)
{
    Stack stack(*this);

    NodeList contextNodes;

    int length = (int) tokens.size();

    for ( ; position < length ; position ++)
        {
        Token tok = tokens[position];
        if (tok.isAxis())
            {
            int pos2 = 0;
            //Do rest of tokens with the nodes we have found so far
            for (unsigned int i = 0 ; i<contextNodes.getLength() ; i++)
                {
                NodePtr contextNode = contextNodes.item(i);
                pos2 = execute(tokens, position, contextNode, result);
                if (pos2 < 0)
                    {
                    return -1;
                    }
                }
            position = pos2;
            }
        else
            {
            if (!tok.execute(stack))
                {
                return -1;
                } 
            }

        }//for

    return position;
}
 /*
  * Runs the test case.
  */
 void runTest()
 {
    Document doc;
    NodeList childList;
    Node childNode;
    NamedNodeMap attrList;
    int nodeType;
    doc = (Document) baseT::load("staff", false);
    childList = doc.getChildNodes();
    for (unsigned int indexN65603 = 0; indexN65603 != childList.getLength(); indexN65603++) {
        childNode = (Node) childList.item(indexN65603);
  nodeType = (int) childNode.getNodeType();
    
    if (baseT::equals(8, nodeType)) {
        attrList = childNode.getAttributes();
    baseT::assertNull(attrList, __LINE__, __FILE__);
    }
    }
    childNode = doc.createComment(SA::construct_from_utf8("This is a comment"));
    attrList = childNode.getAttributes();
    baseT::assertNull(attrList, __LINE__, __FILE__);
    
 }
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList testList;
     Node commentNode;
     String commentNodeName;
     int nodeType;
     doc = (Document) baseT::load("hc_staff", false);
     testList = doc.getChildNodes();
     for (unsigned int indexN65600 = 0; indexN65600 != testList.getLength(); indexN65600++) {
         commentNode = (Node) testList.item(indexN65600);
   commentNodeName = commentNode.getNodeName();
     
     if (baseT::equals("#comment", commentNodeName)) {
         nodeType = (int) commentNode.getNodeType();
     baseT::assertEquals(8, nodeType, __LINE__, __FILE__);
 }
     }
     commentNode = doc.createComment(SA::construct_from_utf8("This is a comment"));
     nodeType = (int) commentNode.getNodeType();
     baseT::assertEquals(8, nodeType, __LINE__, __FILE__);
 
  }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList elementList;
      Node employeeNode;
      NodeList childList;
      Node oldChild;
      Node newChild;
      String childName;
      Node childNode;
      int length;
      std::vector<string_type> actual;
      
      std::vector<string_type> expected;
      
      std::vector<string_type> expectedWithoutWhitespace;
      expectedWithoutWhitespace.push_back(SA::construct_from_utf8("name"));
      expectedWithoutWhitespace.push_back(SA::construct_from_utf8("position"));
      expectedWithoutWhitespace.push_back(SA::construct_from_utf8("salary"));
      expectedWithoutWhitespace.push_back(SA::construct_from_utf8("gender"));
      expectedWithoutWhitespace.push_back(SA::construct_from_utf8("employeeId"));
      
      std::vector<string_type> expectedWithWhitespace;
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("name"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("position"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("salary"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("gender"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("employeeId"));
      expectedWithWhitespace.push_back(SA::construct_from_utf8("#text"));
      
      Node replacedChild;
      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();
      
      if (baseT::equals(13, length)) {
          newChild = childList.item(1);
      oldChild = childList.item(11);
      expected =  expectedWithWhitespace;
      } else {
          newChild = childList.item(0);
      oldChild = childList.item(5);
      expected =  expectedWithoutWhitespace;
      }
        
    replacedChild = employeeNode.replaceChild(newChild, oldChild);
      baseT::assertSame(oldChild, replacedChild, __LINE__, __FILE__);
for (unsigned int indexN65758 = 0; indexN65758 != childList.getLength(); indexN65758++) {
          childNode = (Node) childList.item(indexN65758);
    childName = childNode.getNodeName();
      actual.push_back(childName);
        }
      baseT::assertEquals(expected, actual, __LINE__, __FILE__);
  
   }