multiple root nodes

N

Nik

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;
}
 
H

HK

Nik said:
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.
 
N

Nik

thank you. then I try something else

Nik said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top