Example #1
0
   void test4()
   {
      Arabica::DOM::Element<string_type, string_adaptor> root;
      {
        Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
        root = d.createElement(SA::construct_from_utf8("root"));
        d.appendChild(root);

        root.appendChild(d.createElement(SA::construct_from_utf8("child1")));
        root.appendChild(d.createElement(SA::construct_from_utf8("child2")));
      }
    
      Arabica::DOM::Node<string_type, string_adaptor> c1 = root.getFirstChild();
      Arabica::DOM::Node<string_type, string_adaptor> c2 = root.getLastChild();

      try {
        c1.purgeChild(c2);
      }
      catch(Arabica::DOM::DOMException& e)
      {
        assert(e.code() == Arabica::DOM::DOMException::NOT_FOUND_ERR);
      } // catch

  
      assert(c1 != 0);
      assert(c2 != 0);

      assert(c1.getNextSibling() == c2);
      assert(c2.getPreviousSibling() == c1);
    } // test4
    void test5()
    {
      Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
      Arabica::DOM::DocumentFragment<string_type, string_adaptor> frag = d.createDocumentFragment();
      frag.appendChild(d.createElement(SA::construct_from_utf8("child")));
      frag.appendChild(d.createElement(SA::construct_from_utf8("child2")));
      frag.appendChild(d.createElement(SA::construct_from_utf8("child3")));

      Arabica::DOM::Element<string_type, string_adaptor> elem = d.createElement(SA::construct_from_utf8("root"));
      elem.appendChild(d.createElement(SA::construct_from_utf8("t")));
      assert(elem.getChildNodes().getLength() == 1);

      elem.insertBefore(frag, elem.getFirstChild());
      assert(elem.getChildNodes().getLength() == 4);
      assert(elem.getFirstChild().getNodeName() == SA::construct_from_utf8("child"));
      assert(elem.getLastChild().getNodeName() == SA::construct_from_utf8("t"));
      assert(frag.getChildNodes().getLength() == 0);
    } // test5
Example #3
0
    void test3()
    {
      Arabica::DOM::Element<string_type, string_adaptor> root;
      {
        Arabica::DOM::Document<string_type, string_adaptor> d = factory.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
        root = d.createElement(SA::construct_from_utf8("root"));
        d.appendChild(root);

        root.appendChild(d.createElement(SA::construct_from_utf8("child1")));
	root.appendChild(d.createElement(SA::construct_from_utf8("child2")));
      }

      Arabica::DOM::Node<string_type, string_adaptor> c = root.getFirstChild();
      assert(c.getNextSibling() == root.getLastChild());

      root.purgeChild(c);

      assert(c == 0);
      assert(root.getLastChild() == root.getFirstChild());
   } // test3
Example #4
0
NistXmlTestset::NistXmlTestset(const std::string &file)
		: logger_(logkw::channel = "NistXmlTestset") {
	Arabica::SAX2DOM::Parser<std::string> domParser;
	Arabica::SAX::InputSource<std::string> is(file);
	Arabica::SAX::CatchErrorHandler<std::string> errh;
	domParser.setErrorHandler(errh);
	domParser.parse(is);
	if(errh.errorsReported())
		BOOST_LOG_SEV(logger_, error) << errh.errors();

	Arabica::DOM::Document<std::string> doc = domParser.getDocument();
	if(doc == 0) {
		BOOST_LOG_SEV(logger_, error) << "Error parsing input file: " << file;
		exit(1);
	}

	doc.getDocumentElement().normalize();

	Arabica::XPath::XPath<std::string> xp;

	Arabica::XPath::NodeSet<std::string> docnodes =
		xp.compile("/mteval/srcset/doc").evaluateAsNodeSet(doc.getDocumentElement());
	docnodes.to_document_order();
	BOOST_FOREACH(Arabica::DOM::Node<std::string> n, docnodes)
		documents_.push_back(boost::make_shared<NistXmlDocument>(n));

	outdoc_ = static_cast<Arabica::DOM::Document<std::string> >(doc.cloneNode(true));
	Arabica::DOM::Element<std::string> srcset =
		static_cast<Arabica::DOM::Element<std::string> >(
			xp.compile("/mteval/srcset").evaluateAsNodeSet(outdoc_.getDocumentElement())[0]);

	Arabica::DOM::Element<std::string> tstset = outdoc_.createElement("tstset");
	int docno = 0;
	while(srcset.hasChildNodes()) {
		Arabica::DOM::Node<std::string> n = srcset.removeChild(srcset.getFirstChild());
		tstset.appendChild(n);
		if(n.getNodeType() == Arabica::DOM::Node<std::string>::ELEMENT_NODE &&
				n.getNodeName() == "doc")
			documents_[docno++]->setOutputNode(n);
	}
	tstset.setAttribute("setid", srcset.getAttribute("setid"));
	tstset.setAttribute("srclang", srcset.getAttribute("srclang"));
	tstset.setAttribute("trglang", "TRGLANG");
	tstset.setAttribute("sysid", "SYSID");

	srcset.getParentNode().replaceChild(tstset, srcset);
}