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