Results 1 to 4 of 4
  1. #1
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default how to parse an xml file

    I need to parse an XML file hello.xml which is in WEB-INF/classes folder
    My Action class calls a helper class called XMLMenuBuilder which needs to parse the menu.xml

    the code:

    LogonAction.java
    Java Code:
    
    XMLMenuBuilder builder = new XMLMenuBuilder();
    Vector menuV = (Vector)builder.renderMenu();
    XMLMenuBuilder.java
    Java Code:
    public Vector renderMenu() throws AppException
    {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document = builder.parse( new File(xmlfile) );
    }

    My Problem is how can I make the builder.parse access the menu.xml file under the WEB-INF/classes folder instead of searching for it on the file system
    any ideas?

  2. #2
    sathish_2111 is offline Member
    Join Date
    Jul 2007
    Posts
    17
    Rep Power
    0

    Default

    If you are using .war file and it has WEB-INF/classes folder and also your class files...then you can use xmlfile = "WEB-INF/classes/menu.xml"

  3. #3
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Because the file is in your classes folder you can use the ClassLoader to get at it. Try this:
    Java Code:
    builder.parse(this.getClass().getClassLoader().getResourceAsStream(xmlFile));
    That will get you what you want.

  4. #4
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

Similar Threads

  1. how to Parse int to a string variable
    By raj reddy in forum Java Servlet
    Replies: 10
    Last Post: 01-09-2009, 08:41 PM
  2. SAX Parse
    By bluefloyd8 in forum New To Java
    Replies: 1
    Last Post: 01-25-2008, 04:57 PM
  3. How to parse in html
    By paty in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 01:29 AM
  4. Parse error
    By Eric in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 07:32 PM
  5. How to parse HTML tags
    By Ada in forum Advanced Java
    Replies: 1
    Last Post: 05-31-2007, 10:42 PM

Posting Permissions

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