From: "Han Ming Ong" <[EMAIL PROTECTED]> > On Thursday, February 6, 2003, at 11:08 AM, James Strachan wrote: > > > I don't quite follow your second suggestion but I think it assumes a > > List > > containing all elements anywhere in the tree? In the document you > > describe > > the doc.content() will be a list of one element (<root>) > > > > Sorry, the first line should be > > /* this would be the equivalent of slowly using > DocumentFactory.createElement() to create "foo" and then "bar" */ > Element whatever = DocumentHelper.makeElement("foo/bar"); > > and the last line should be > > parent.content().add(pos, whatever); > > Hope that it makes sense now, Han Ming
Unfortunately not :-) XML documents only have a single root element. So typically doc.content() will only contain one Element object. The reason that the makeElement() method takes a branch node is so that it can navigate down through the tree of nodes, adding new elements as it goes. e.g. Document doc = DocumentHelper.createDocument(); DocumentHelper.makeElement(doc, "a/b/c"); DocumentHelper.makeElement(doc, "a/b/d"); The first call to makeElement() would add <a>, <b>, <c> elements to the document (and doc.content().size() would equal 1) The second call to makeElement() would only add a child <d> node on the existing <c> node. After running the above code these assertions would be true doc.content().size() == 1 doc.selectNodes("/a/b/*").size() = 2 Element b = (Element) doc.selectSingleNode("a/b"); b.content().size() == 2 Does that clear things up any? James ------- http://radio.weblogs.com/0112098/ __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user