Nesting of complex type

Sunderam P <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
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/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.