[jdom-interest] jdom build a JAva Object with a file XML with morethan one item

Christian Avril christian.avril at dpma.finances.gouv.fr
Thu Jan 27 10:09:58 PST 2005


Hello Phil, 

Thanks 
It's right, I can read the apidocs and that helps.

In my case, I think it's better to use a DOM, and not a SAX.

And then, retrieve each Element and Values 

For example, build into a Document , and not only valid them , then parse it
 
               // builder.build(fichierxml);
                Document doc = builder.build(fichierxml);
                Element applications = doc.getRootElement();
                Iterator itr = (applications.getChildren()).iterator();
                while (itr.hasNext()) {
                    Element app = (Element) itr.next();
                    .../...
                    log.info(app.getAttribute("name").getValue());
                    .../...
                }
  ----- Original Message ----- 
  From: Phil Weighill-Smith 
  To: Christian Avril ; jdom-interest at jdom.org 
  Sent: Wednesday, January 26, 2005 10:12 PM
  Subject: RE: [jdom-interest] jdom build a JAva Object with a file XML with morethan one item


  Using JDOM you can read this XML file (see http://www.jdom.org/docs/apidocs/org/jdom/input/SAXBuilder.html) into a JDOM Document (see http://www.jdom.org/docs/apidocs/org/jdom/Document.html). This document will have a root node called "applications" (see http://www.jdom.org/docs/apidocs/org/jdom/Document.html#getRootElement()). This root node will have two child elements, both called "application" (see http://www.jdom.org/docs/apidocs/org/jdom/Element.html).
   
  Either using the JDOM API (to which these links take you) or using the JDOM XPath API (see http://www.jdom.org/docs/apidocs/org/jdom/xpath/XPath.html) you can traverse this DOM to read the data (attributes, child elements etc.).
   
  Hope that helps,
   
  Phil :n)

  -----Original Message----- 
  From: Christian Avril [mailto:christian.avril at dpma.finances.gouv.fr] 
  Sent: Wed 26/01/2005 18:17 
  To: jdom-interest at jdom.org 
  Cc: 
  Subject: [jdom-interest] jdom build a JAva Object with a file XML with morethan one item


  Hello , 

  Have You Please an example with an XML File and more than one item.
  I would build this file in a Java Object. But there are more than one "application"
  See
  <?xml version="1.0" encoding="utf-8"?>
  <applications  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="applications.xsd">
     <application key="appli1">
    <rule>rule_a</rule>
          <role>admin</role>
          <permission>0</permission>
          <population>allperson
             <filter>ou=ldapfilter123</filter>
          </population>
     </application>
     <application key="appli1">
    <rule>rule_u</rule>
          <role>user</role>
          <permission>1</permission>
          <population>users
              <filter>ou=ldapfilter456</filter>
          </population>
     </application>
     <application key="appli2">
    <rule>rule_a</rule>
          <role>admin</role>
          <permission>2</permission>
          <population>allperson
              <filter>ou=ldapfilter789</filter>
          </population>
      </application>
  </applications>

  Thanks 

  Chris


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050127/2a057f91/attachment.htm


More information about the jdom-interest mailing list