I'd personally use SAX to parse this directly into the target data structure. You could also have a look at CookXML (http:// cookxml.yuanheng.org/) which provides a litte framework exactly for parsing XML data into Java. Another alternative might be JAXB.
Cheers, Richard Am 23.06.2007 um 17:03 schrieb H s: > what im asking here is that is this the optimzed code to get all the > nodes.... > > - H > >> From: "Anand Raman" <[EMAIL PROTECTED]> >> To: "H s" <[EMAIL PROTECTED]> >> CC: dom4j-user@lists.sourceforge.net >> Subject: Re: [dom4j-user] Code optimization for parsing XML >> Date: Sat, 23 Jun 2007 06:42:28 +0530 >> >> hi H s, >> >> Not sure what you really want to do here. By parsing do you mean you >> would like to extract all the attributes or do something else. >> >> I would recommend using XPath if you would like to quickly extract >> all >> the nodes. The quick start guide on dom4j is a excellent source of >> quick examples to help you get started. >> >> Cheers >> anand raman >> >> On 6/22/07, H s <[EMAIL PROTECTED]> wrote: >>> Hi there, >>> >>> Here is the piece of code which I'm using to parse the given >>> XML . Is >> there >>> a better way than this ? >>> >>> <acl_config > >>> <acl name="Test"> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_DELETE"/> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_NONE"/> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_WRITE"/> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_RELATE"/> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_NONE"/> >>> <privilege group="testaclgroupharjit" >> permission="PERMIT_VERSION"/> >>> </acl> >>> <acl name="Test1"> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> <privilege group="testaclgroupharjit2" >> permission="PERMIT_BROWSE"/> >>> </acl> >>> </acl_config> >>> >>> >>> List aclConfigObjectList = new ArrayList(); >>> String aclXPath = "/acl_config/*"; >>> XPath xpathSelector = >> DocumentHelper.createXPath(aclXPath); >>> List results = xpathSelector.selectNodes >>> (xmldocument); >>> Attribute aclName; >>> Attribute groupName; >>> Attribute permission; >>> String aclValue = null; >>> ACLConfig aclConfig = null; >>> GroupConfig groupConfig = null; >>> Vector groups = null; >>> if (results != null) { >>> for (int i = 0; i < results.size(); ++i) { >>> Element e = (Element) results.get >>> (i); >>> if ((aclName = e.attribute(NAME)) != >> null) { >>> aclConfig = new ACLConfig(); >>> >> aclConfig.setAclName(aclName.getValue()); >>> groups = new Vector(); >>> int iNodeCount = >>> e.nodeCount(); >>> for (int iNodeIndex = 0; >> iNodeIndex < iNodeCount; ++iNodeIndex) { >>> Node node = >> e.node(iNodeIndex); >>> if (node instanceof >> Element) { >>> Element >>> group = >> (Element) node; >>> >>> groupConfig = >> new GroupConfig(); >>> if >> (group.attribute(GROUP) != null) { >>> >> groupName = group.attribute(GROUP); >>> >> groupConfig.setGroupName(groupName.getValue()); >>> } >>> if >> (group.attribute(PERMISSION) != null) { >>> >> permission = group.attribute(PERMISSION); >>> >> groupConfig >>> >> .setPermission(lookupPermission(permission >>> >> .getValue())); >>> >> groups.add(groupConfig); >>> } >>> } >>> } >>> >>> if (groups.size() > 0) { >>> >> aclConfig.setGroupVector(groups); >>> } >>> >> aclConfigObjectList.add(aclConfig); >>> } >>> } >>> >>> _________________________________________________________________ >>> Hotmail to go? Get your Hotmail, news, sports and much more! >>> http://mobile.msn.com >>> >>> >>> >> --------------------------------------------------------------------- >> ---- >>> This SF.net email is sponsored by DB2 Express >>> Download DB2 Express C - the FREE version of DB2 express and take >>> control of your XML. No limits. Just data. Click to get it now. >>> http://sourceforge.net/powerbar/db2/ >>> _______________________________________________ >>> dom4j-user mailing list >>> dom4j-user@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/dom4j-user >>> >> >> --------------------------------------------------------------------- >> ---- >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> dom4j-user mailing list >> dom4j-user@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/dom4j-user >> > > _________________________________________________________________ > Get a preview of Live Earth, the hottest event this summer - only > on MSN > http://liveearth.msn.com?source=msntaglineliveearthhm > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > dom4j-user mailing list > dom4j-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/dom4j-user ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ dom4j-user mailing list dom4j-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-user