hi helper, I would like to create an xml file using multiple collection, xml example: <chart a=111 b=222> <tag1> <c=111 d=222> <e=111 f=888> </tag1> <tag2> <c=111 d=222> <e=111 f=888> </tag2> </chart>
I need to create a function that will get only collections (of any sort) that will have all the above data and will be able to iterate through those and create the above result as StringBuffer. I will use Element & Document of course... The main issue here is to create a generic function that will get collections and create xml data string/file Thanks a lot Yossi
hey, ok, but my main issue is to have collections inside collection that will hold the data, I dont want the code to look like this: Digester digester = new Digester(); // This method pushes this (SampleDigester) class to the Digesters // object stack making its methods available to processing rules. digester.push(this); // This set of rules calls the addDataSource method and passes // in five parameters to the method. digester.addCallMethod("datasources/datasource", "addDataSource", 5); digester.addCallParam("datasources/datasource/name", 0); digester.addCallParam("datasources/datasource/driver", 1); digester.addCallParam("datasources/datasource/url", 2); digester.addCallParam("datasources/datasource/username", 3); digester.addCallParam("datasources/datasource/password", 4);
// This method starts the parsing of the document. digester.parse("datasource.xml");
I would like to create a function that will get a single collection (key value type) that will hold inside more collections, and to iterate through them and create the xml. How do I do that? Can you give me a simple example with the simple xml eample I wrote above? Thanks again man Yossi
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
Element book = document.createElement("book"); book.setAttribute("id", "javanut4"); document.appendChild(book); for(int i = 1; i <= 3; i++) { Element chapter = document.createElement("chapter"); Element title = document.createElement("title"); title.appendChild(document.createTextNode("Chapter " + i)); chapter.appendChild(title); chapter.appendChild(document.createElement("para")); book.appendChild(chapter); }
can you think of a generic function that will create the above without the need to hard code the name of the elements inside the function ,such as book, & id & javanut4? thanks