Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

multiple root nodes

Thread view: 
Nik - 09 May 2005 15:38 GMT
I created a XML file with java which looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
- <music>
- <mp3>
  <name>Audioplacid - Heaven 0.9.1.mp3</name>
  <size>11911528</size>
  <path>D:\Mp3</path>
  <ext>mp3</ext>
  <added>1112185739331</added>
  </mp3>
- <mp3>
  <name>E-Nature - Silent Nature.mp3</name>
  <size>12449920</size>
  <path>D:\Mp3\E-Nature</path>
  <ext>mp3</ext>
  <added>1065606457000</added>
  <comment />
  <rating />
  <hidden />
  </mp3>
.....

I tried several times to add more than one root node to the xml file but
everytime I want to do that I either get an error or the first root node
will be overwritten with the second root node.

is it possible to have more than one root node in the same file?
any tips or suggestions?

my current java code for this function looks like this:

public Document addXmlContent(String directory, String discName, String
archiveName)
    throws ParserConfigurationException {

        Vector filesInDirectory = fillDirInVector(directory);
       
        /* get an xml doc */
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document xmldoc = builder.newDocument();
       
        // create the root node
        // NAME OF ARCHIVE
        Element docRoot = xmldoc.createElement(archiveName);
       
        // VECTOR READING LOOP START
        for (int i = 0; i < filesInDirectory.size(); i += 5) {
       
           /* create a row node */
           // NAME OF DISC
           Element rowElement = xmldoc.createElement(discName);
       
           /* create the column nodes and append each to the row node */
           Element columnElement;
           Text textData;
       
           // FILE NAME
           columnElement = xmldoc.createElement("name");
           textData = xmldoc.createTextNode((String) filesInDirectory
                   .elementAt(i));
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // FILE SIZE
           columnElement = xmldoc.createElement("size");
           textData = xmldoc.createTextNode((String) filesInDirectory
                   .elementAt(i + 1));
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // SUBPATH IN DIRECTORY
           columnElement = xmldoc.createElement("path");
           textData = xmldoc.createTextNode((String) filesInDirectory
                   .elementAt(i + 2));
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // FILE EXTENSION
           columnElement = xmldoc.createElement("ext");
           textData = xmldoc.createTextNode((String) filesInDirectory
                   .elementAt(i + 3));
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // LAST MODIFICATION DATE
           columnElement = xmldoc.createElement("added");
           textData = xmldoc.createTextNode((String) filesInDirectory
                   .elementAt(i + 4));
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // PERSONAL COMMENT FOR FILE
           columnElement = xmldoc.createElement("comment");
           textData = xmldoc.createTextNode("");
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // RATE SPECIFIC FILE
           columnElement = xmldoc.createElement("rating");
           textData = xmldoc.createTextNode("");
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           // SHOW ARCHIVE ONLY IF PASSWORD WAS ENTERED
           columnElement = xmldoc.createElement("hidden");
           xmldoc.createTextNode("n");
           columnElement.appendChild(textData);
           rowElement.appendChild(columnElement);
       
           /* append the row node to the root node */
           docRoot.appendChild(rowElement);
       
           /* VECTOR READING LOOP END */
        }
       
        /* append the root node to the empty document */
        xmldoc.appendChild(docRoot);
       
        return xmldoc;
    }
HK - 09 May 2005 15:50 GMT
> I created a XML file with java which looks like this:
[...]
> is it possible to have more than one root node in the same file?
> any tips or suggestions?

No way. That's why it is called a root node.

 Harald.
Nik - 09 May 2005 16:09 GMT
thank you. then I try something else

>>I created a XML file with java which looks like this:
>
[quoted text clipped - 6 lines]
>
>   Harald.
Darryl Pierce - 10 May 2005 12:43 GMT
> is it possible to have more than one root node in the same file?

No.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.