Java Mailing List Archive

http://www.junlu.com/

Home » JDOM Projects »

[jdom-interest] Nesting of complex type

Sunderam P

2008-03-16

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,
I am trying to create an XML with following structure.
 
<DocRoot>
    <Folder name="xyz">
        <Folder name="abc">
            <File>File2</File>
             <File>File3</File>
        </Folder>
        <File>File1</File>
    </Folder>
</DocRoot>

Following is the code snippet of what I have right now.

    //Loop through the list of files & directory to generate XML file
    private void GenerateXML(String []DirectoryListing) throws IOException{
        int i=0;
        File CheckContent;
        XMLGenerator.setRootElement(XMLRoot);
         File CurrentDirectory;
        for(i=0;i< DirectoryListing.length; i++)
        {
              //file/directory
            String FolderContent = DirectoryListing[i];
            CheckContent = new File(FolderContent);
             if (CheckContent.isFile() == true)
             {
                  Element Folder = new Element("Folder");
                                CurrentDirectory = new File (FolderContent);
                                Folder.addContent(CurrentDirectory.getParent());
                                Element FileName = new Element("FileName");
                                FileName.addContent(FolderContent);
                                Element FileLength = new Element("Length");
                                FileLength.addContent(String.valueOf(CheckContent.length()));
                                XMLRoot.addContent(Folder);
                                XMLRoot.addContent(FileName);
                XMLRoot.addContent(FileLength);
             }

            if (CheckContent.isDirectory()==true)
            {
                String [] FileList = ReadDirectory(FolderContent);
                //Element Directory = new Element("SubDirectory");
               // Directory.addContent(FolderContent);
              //  XMLRoot.addContent(Directory);
                GenerateXML(FileList);
            }
        }
    }

I get the following XML from the above snippet
<SharedFolder>
    <Folder>Directory</Folder>
    <FileName>text file.txt</FileName>
     <Length>9</Length>
     <Folder>Folder</Folder>
     <FileName>text file2.txt</FileName>
     <Length>9</Length>
</SharedFolder>

My directory is as follows
C:\Directory\ text file.txt , Folder\, Folder\text file2.txt.

Any suggestions?

thanks


Never miss a thing. Make Yahoo your homepage.
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.