title: Parsing a simple XML document with JAXP(JEE6)
body: <p>I want to create an authorization filter for my web app(To be able to restrict access to certain pages).</p>
  
  <p>I created a simple .xml file with the pages that each user is allowed to visit:</p>
  
  <pre><code>  &lt;access&gt;
      &lt;buyer&gt;
          &lt;page&gt;buyoffer.xhtml&lt;/page&gt;
          &lt;page&gt;faq.xhtml&lt;/page&gt;
          &lt;page&gt;index.jsp&lt;/page&gt;
          &lt;page&gt;login.xhtml&lt;/page&gt;
          &lt;page&gt;main.xhtml&lt;/page&gt;
          &lt;page&gt;registrationSucceded.xhtml&lt;/page&gt;     
      &lt;/buyer&gt;
      &lt;seller&gt;
          &lt;page&gt;sellerpanel.xhtml&lt;/page&gt;
          &lt;page&gt;faq.xhtml&lt;/page&gt;
          &lt;page&gt;index.jsp&lt;/page&gt;
          &lt;page&gt;login.xhtml&lt;/page&gt;
          &lt;page&gt;main.xhtml&lt;/page&gt;
          &lt;page&gt;registrationSucceded.xhtml&lt;/page&gt;     
      &lt;/seller&gt;
      &lt;administrator&gt;
          &lt;page&gt;sellerpanel.xhtml&lt;/page&gt;
          &lt;page&gt;faq.xhtml&lt;/page&gt;
          &lt;page&gt;index.jsp&lt;/page&gt;
          &lt;page&gt;login.xhtml&lt;/page&gt;
          &lt;page&gt;main.xhtml&lt;/page&gt;
          &lt;page&gt;registrationSucceded.xhtml&lt;/page&gt;     
      &lt;/administrator&gt;
  &lt;/access&gt;
  </code></pre>
  
  <p>Then i need to do parsing to extract the value of the pages, to be able to create conditions to allow or redirect(Depending). I just need somebody to tell be how to extract the values of those pages from the xml. This is what i did till now:</p>
  
  <pre><code>public class RestrictPageFilter implements Filter {
  
      private FilterConfig fc;
      private DocumentBuilder builder;
      private Document document;
  
      public void init(FilterConfig filterConfig) throws ServletException {
          // The easiest way to initialize the filter
          fc = filterConfig;
          // Get the file that contains the allowed pages
          File f = new File("/allowedpages.xml");
          // Prepare the file parsing
          try {
              builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
              document = builder.parse(f);
          } catch (ParserConfigurationException e) {
              e.printStackTrace();
          } catch (SAXException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      public void doFilter(ServletRequest request, ServletResponse response,
              FilterChain chain) throws IOException, ServletException {
  
          HttpServletRequest req = (HttpServletRequest) request;
          HttpServletResponse resp = (HttpServletResponse) response;
          HttpSession session = req.getSession(true);
          String pageRequested = req.getRequestURL().toString();
  
          // Get the value of the current logged user
          Role currentUser = (Role) session.getAttribute("userRole");
          if (currentUser != null) {
              if(currentUser.getType().equals("BUYER")) {
                  //Loop BUYER Element of the .xml
                  //if pageRequested.contains(value of the page at buyer element)             
                  // chain.doFilter(request, response);
                  // Else
                  // Redirect the user to the main page
              }
              else if(currentUser.getType().equals("SELLER")) {
                  //Same as above just for seller element
              }
              else if(currentUser.getType().equals("ADMINISTRATOR")) {
                  //Same as above just for administrator element
              }           
          }
      }
  
      public void destroy() {
          // Not needed
      }
  }
  </code></pre>
  
  <p>In the comments inside the doFilter method is explained what i need to do. Could someone give me a tip on how i should iterate through the file to find the page names for each of the user types? I try to follow JAXP examples from the internet, but they are more complex than what i need.</p>
  
  <p><b>Update</b>
  The xml is stored in WEB-INF/classes</p>