Package org.htmlparser.util

Examples of org.htmlparser.util.NodeIterator


  public void testToString() throws ParserException {
    assertEquals("Body", "BODY: Yahoo!", bodyTag.toString());
  }

  public void testAttributes() {
    NodeIterator iterator;
    Node node;
    Hashtable attributes;

    try {
      createParser("<body style=\"margin-top:4px; margin-left:20px;\" title=\"body\">");
      parser.addScanner(new BodyScanner("-b"));
      iterator = parser.elements();
      node = null;
      while (iterator.hasMoreNodes()) {
        node = iterator.nextNode();
        if (node instanceof BodyTag) {
          attributes = ((BodyTag) node).getAttributes();
          assertTrue("no style attribute", attributes.containsKey("STYLE"));
          assertTrue("no title attribute", attributes.containsKey("TITLE"));
        } else
          fail("not a body tag");
        assertTrue("more than one node", !iterator.hasMoreNodes());
      }
      assertNotNull("no elements", node);
    } catch (ParserException pe) {
      fail("exception thrown " + pe.getMessage());
    }
View Full Code Here


    actual = removeEscapeCharacters(actual);

    Parser expectedParser = Parser.createParser(expected);
    Parser resultParser = Parser.createParser(actual);

    NodeIterator expectedIterator = expectedParser.elements();
    NodeIterator actualIterator = resultParser.elements();
    displayMessage = createGenericFailureMessage(displayMessage, expected, actual);

    Node nextExpectedNode = null, nextActualNode = null;
    do {
      nextExpectedNode = getNextNodeUsing(expectedIterator);
View Full Code Here

    URL url;
    HttpURLConnection connection;
    StringBuffer buffer;
    PrintWriter out;
    boolean pass;
    NodeIterator enumeration;
    Node node;
    StringNode string;

    try {
      url = new URL("http://www.canadapost.ca/tools/pcl/bin/cp_search_response-e.asp");
      connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Referer", "http://www.canadapost.ca/tools/pcl/bin/default-e.asp");
      connection.setDoOutput(true);
      connection.setDoInput(true);
      connection.setUseCaches(false);
      buffer = new StringBuffer(1024);
      buffer.append("app_language=");
      buffer.append("english");
      buffer.append("&");
      buffer.append("app_response_start_row_number=");
      buffer.append("1");
      buffer.append("&");
      buffer.append("app_response_rows_max=");
      buffer.append("9");
      buffer.append("&");
      buffer.append("app_source=");
      buffer.append("quick");
      buffer.append("&");
      buffer.append("query_source=");
      buffer.append("q");
      buffer.append("&");
      buffer.append("name=");
      buffer.append("&");
      buffer.append("postal_code=");
      buffer.append("&");
      buffer.append("directory_area_name=");
      buffer.append("&");
      buffer.append("delivery_mode=");
      buffer.append("&");
      buffer.append("Suffix=");
      buffer.append("&");
      buffer.append("street_direction=");
      buffer.append("&");
      buffer.append("installation_type=");
      buffer.append("&");
      buffer.append("delivery_number=");
      buffer.append("&");
      buffer.append("installation_name=");
      buffer.append("&");
      buffer.append("unit_numbere=");
      buffer.append("&");
      buffer.append("app_state=");
      buffer.append("production");
      buffer.append("&");
      buffer.append("street_number=");
      buffer.append(number);
      buffer.append("&");
      buffer.append("street_name=");
      buffer.append(street);
      buffer.append("&");
      buffer.append("street_type=");
      buffer.append(type);
      buffer.append("&");
      buffer.append("test=");
      buffer.append("&");
      buffer.append("city=");
      buffer.append(city);
      buffer.append("&");
      buffer.append("prov=");
      buffer.append(province);
      buffer.append("&");
      buffer.append("Search=");
      out = new PrintWriter(connection.getOutputStream());
      out.print(buffer);
      out.close();
      parser = new Parser(connection);
    } catch (Exception e) {
      throw new ParserException("You must be offline! This test needs you to be connected to the internet.", e);
    }

    pass = false;
    for (enumeration = parser.elements(); enumeration.hasMoreNodes();) {
      node = enumeration.nextNode();
      if (node instanceof StringNode) {
        string = (StringNode) node;
        if (-1 != string.getText().indexOf(postal_code))
          pass = true;
      }
View Full Code Here

    File file;
    PrintWriter out;
    Parser parser;
    Node nodes[];
    int i;
    NodeIterator enumeration;

    path = System.getProperty("user.dir");
    if (!path.endsWith(File.separator))
      path += File.separator;
    file = new File(path + "delete_me.html");
    try {
      out = new PrintWriter(new FileWriter(file));
      out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>test</title>");
      out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
      out.println("</head>");
      out.println("<body>");
      out.println("This is a test page ");
      out.println("</body>");
      out.println("</html>");
      out.close();
      parser = new Parser(file.getAbsolutePath());
      nodes = new Node[30];
      i = 0;
      for (enumeration = parser.elements(); enumeration.hasMoreNodes();) {
        nodes[i] = enumeration.nextNode();
        i++;
      }
      assertEquals("Expected nodes", 12, i);
    } catch (Exception e) {
      fail(e.toString());
View Full Code Here

   * that after the enumeration is created, that the charset has changed to
   * the correct value.
   */
  public void testHTMLCharset() {
    Parser parser;
    NodeIterator enumeration;

    try {
      parser = new Parser("http://www.sony.co.jp", Parser.noFeedback);
      assertEquals("Character set by default is ISO-8859-1", "ISO-8859-1", parser.getEncoding());
      enumeration = parser.elements();
View Full Code Here

  Vector formChildren;

  public void setUp() throws Exception {
    Parser parser = Parser.createParser(FormScannerTest.FORM_HTML);
    parser.registerScanners();
    NodeIterator e = parser.elements();
    Node node = e.nextNode();
    formTag = (FormTag) node;
    formChildren = new Vector();
    for (SimpleNodeIterator se = formTag.children(); se.hasMoreNodes();) {
      formChildren.addElement(se.nextNode());
    }
View Full Code Here

TOP

Related Classes of org.htmlparser.util.NodeIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.