Results 1 to 2 of 2
  1. #1
    superman1938 is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default Interface Question

    I am trying to create my own custom Node class. I am implementing the Node class and that seems to be working fine. I now need to use the NodeList class. I am grabbing the first element from the NodeList class and I need to somehow cast it to my CustomNode class...
    String responseString; //a string of XML
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(responseString))); //convert to a DOM document
    NodeList selected = document.getDocumentElement().getElementsByTagName (element); //Select the correct node
    CustomNode selectedNode = selected.item(0);//ERROR here selected.item(0) returns a node and I am trying to use a class that implements the Node interface.

    What am I doing wrong?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    Java Code:
    CustomNode selectedNode =[COLOR="Red"] (CustomNode) [/COLOR]selected.item(0);
    ?

Similar Threads

  1. Java Native Interface Question
    By RichWade in forum Advanced Java
    Replies: 20
    Last Post: 11-29-2010, 06:26 PM
  2. question on listener interface
    By Minu in forum Java Servlet
    Replies: 1
    Last Post: 01-16-2009, 10:33 AM
  3. Interface question in java
    By tony404 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2008, 11:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •