convert Item to dom.Node

Help
pfc_caw
2004-11-19
2012-10-08
  • pfc_caw

    pfc_caw - 2004-11-19

    hi!
    My query produce a sequence of Item objects. I want to convert these objects to org.w3c.dom.Node. I tried to cast Item to NodeInfo but i dont get anything.
    I use DOM Tree because I use Tidy to convert HTML to XTHML and get the DOM Document.
    Thank you

     
    • Michael Kay

      Michael Kay - 2004-11-19

      You need to explain (a) how you are invoking the query, and (b) how you are processing the results. Does the cast to NodeInfo succeed? If so, what are you trying to do with the resulting NodeInfo? What exactly do you mean when you say that "you don't get anything"?

      Michael Kay

       
    • pfc_caw

      pfc_caw - 2004-11-21

      The query
      //img

      final SequenceIterator iter = exp.iterator(dynamicContext);
      while (true) {
      Item item = iter.next();
      if (item == null) {
      break;
      }
      org.w3c.dom.Node node=(org.w3c.dom.Node)item;
      System.out.println("item:"+item.getStringValue());
      System.out.println("node:"+node.getNodeType());
      }

      This is the code. I use println() to check. it Only prints:
      item:
      node:
      item:
      node:
      ...

       
      • Michael Kay

        Michael Kay - 2004-11-21

        getStringValue() probably displays an empty string because the img element has no content.

        But I can't see any possible reason why getNodeType() should display as an empty string, because the method returns a short. If you haven't got a Java debugger to show more clearly what's going on, try displaying item.getClass() to see what the implementation class is, and displaying the name of the node.

         

Log in to post a comment.