Re: multiple root nodes



Hi,

No, you can't have multiple root nodes in an XML document.

Why would you need this kind of thing ?

Regards,

Arnaud

"Nik" <waves@xxxxxx> a écrit dans le message news:
427f75cc$0$149$fb624d75@xxxxxxxxxxxxxxxxxxxxxx
> 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;
> }


.



Relevant Pages

  • Re: multiple root nodes
    ... everytime I want to do that I either get an error or the first root node ... Element columnElement; ... columnElement = xmldoc.createElement; textData = xmldoc.createTextNodefilesInDirectory ...
    (comp.lang.java.help)
  • multiple root nodes
    ... 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. ...
    (comp.lang.java.help)
  • multiple root nodes
    ... 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. ...
    (comp.lang.java.programmer)
  • Re: Getting to the root node of an xml document
    ... I have some old code around here that reads and then prints out an XML file. ... It's handy because it lets you see the whole structure of the XML file; I think the root node of the tree structure isn't the root node of the document itself. ... public EditorJFrame(String filename) ... private void preOrderXml(org.w3c.dom.Node docNode, DefaultMutableTreeNode treeNode, int level) ...
    (comp.lang.java.help)
  • Re: BizTalk 2004 :: merging a multiple root node message as output
    ... If you really have a legacy system that is not using well-formed xml (or ... > I have a typical xml message as input (single root node) and I need to map ... > to a message which contains multiple root nodes. ...
    (microsoft.public.biztalk.general)