Solved

Iterate .xml files in a directory using Java/DOM4J

Posted on 2006-07-20
13
605 Views
Last Modified: 2012-05-05
I need to iterate .xml files in a directory, once I have a handle to the file I will get a read stream and do other things which I'm fine with - just need a quick and dirty way to iterate the files in the directory.  I'm using Java and DOM4J so if I can do it within those packages it would be great.

Thanks in advance.
pt_wood.
0
Comment
Question by:pt_wood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 300 total points
ID: 17146764
File dir = new File("somedir");
dir.listFiles(new FileFilter() {
    pubic boolean accept(File pathname) {
        return pathname.getName().toLowerCase().endsWith(".xml");
    }
});
0
 
LVL 37

Accepted Solution

by:
zzynx earned 200 total points
ID: 17146936
CEHJ is right.
And in case you wouldn't know how to iterate:

File dir = new File("somedir");
File[] myFiles = dir.listFiles(new FileFilter() {
    public boolean accept(File pathname) {
        return pathname.getName().toLowerCase().endsWith(".xml");
    }
});
// Iterate through your files:
for (int i=0, m=myFiles.length; i<m; i++) {
   File theFile = myFiles[i];
   // Do with your file what you want...
}
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17146964
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 17147184
:-)
0
 

Author Comment

by:pt_wood
ID: 17147212
Thanks - i accepted CEHJ's reply - and zzynx's iteration tip helped and mukundha's link gives another approach if I get hung up.  -pt_wood.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 17165619
>> zzynx's iteration tip helped
Then I wonder why I'm not part of a split
(And I also wonder what the comment should have been to deserve an A grade?)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17165829
pt_wood - if you want, we can get the question reopened so that zzynx is included
0
 

Author Comment

by:pt_wood
ID: 17179966
ok can we do that - I couldn't figure out how to split the points - that's why I gave them all to CEHJ.

Also I'd like to change the grade to A also.

Thanks.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 17181692
>> ok can we do that
I'll ask to reopen this Q.
Once reopened you can close it again using a split

>> I couldn't figure out how to split the points
Here's what EE's halp page says about that:

Can I split the points?
Yes. Scroll down to the bottom of the question, just above the text box, and click the "Split Points" link. Select the radio button of the comment who you want to Accept as the Accepted Answer. Only one button can be selected. Set the point value (a text box above the comment) of how much you want this person to receive of the points. Then set the point values for each of the experts comments to whom you want to allocate points and these will be considered Assisted Answers in helping you resolve the issue. Double check your information and then click the Submit button at the bottom of the page. One note: the total points of the splits must equal the amount you asked the question for itself, and no person can receive fewer than 20 points.
0
 

Author Comment

by:pt_wood
ID: 17188397
I split 300/200 CEHJ/zzynx and changed grade to A.  Thank you.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 17190445
Thanx 4 axxepting
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17190703
:-)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to debug htl and js pages 8 80
Html Table Looping (part 2) 5 42
Github api to fetch the number of collaborators in a git repo 1 70
using executorService 3 25
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question