Results 1 to 6 of 6

Thread: XML parser

  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Question XML parser

    I have programed an file to create an XML file.
    But that was programmed myself.

    Now I would like to create one with an DOM parser.
    So I start with an:

    Java Code:
     
    Element data = new Element("data");
    But then I get an error:
    org.w3c.dom.Element is abstract; cannot be instantiated

    What does that meen?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Element is an interface so you can`t create an object of that class!
    Element (Java 2 Platform SE v1.4.2)

    You have to create a DocumentBuilder, respectively a document with builder.newDocument() and then you can create an Element with (Element) document.createElement("data");

    See: Creating and Manipulating a DOM
    Last edited by eRaaaa; 03-18-2011 at 09:43 PM.

  3. #3
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    How exactly do you meen that?

    Becose it is a school project and for this I need to read in a txt file, and make there an XML file from. At the moment I have:

    Public class ......
    Public static void main ......

    And then I have the Element ....... = new Element(...);

    try {


    After the try we read we file we would like to transform to an XML file.
    That is how the program would look like.

    But do you meen I should take away the public static void main line?

  4. #4
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    Is this a good tutorual: www.ibm.com/developerworks/java/library/j-dom/
    Becose I do that exactly, but also no luck. :(

  5. #5
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Ok tell us first which library do you want to use? JDOM ? Then you have used the wrong import !
    Don`t use import org.w3c.dom.Element; ,
    use import org.jdom.Element; instead of that, then you are able to instantiate an Element object !
    Last edited by eRaaaa; 03-21-2011 at 06:22 PM.

  6. #6
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    I was thinking there only was DOM and SAX. O_o
    Will have a look at this one then.
    Hopefully then it will work.
    Thanks for the help. :)

    I think I am also gonna look to the w3c.dom tutorial.
    Becose that sounds better.
    Then I also don't need to install everything all the time if I wouk on another computer.
    Last edited by Lund01; 03-24-2011 at 06:04 PM.

Similar Threads

  1. Parser API
    By sruti_mohan in forum Advanced Java
    Replies: 0
    Last Post: 06-09-2008, 07:23 AM
  2. JSP Parser????
    By chathu03j in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-10-2008, 12:08 PM
  3. DNS name parser 1.2.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-14-2007, 08:21 PM
  4. XML Parser
    By samfuerte in forum XML
    Replies: 1
    Last Post: 07-14-2007, 04:14 PM
  5. Parser
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 07:08 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
  •