[jdom-interest] Nesting of complex type
Sunderam P
sunderam08 at yahoo.com
Sun Mar 16 12:34:38 PDT 2008
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20080316/940dd918/attachment.htm
More information about the jdom-interest
mailing list