public Document writeXml() { if (this.relationships == null) { return this.xml; } int counter = 1; for (Iterator it = this.relationships.iterator(); it.hasNext(); ) { Object o = it.next(); if (o instanceof Relationship) { Relationship r = (Relationship) o; if (r.id.equals("NONE")) { r.id = "rId" + counter; counter++; } this.root.appendChild(r.write(this.xml)); } else { SubDocument r = (SubDocument) o; if (r.id.equals("NONE")) { r.id = "rId" + counter; counter++; } this.root.appendChild(r.write(this.xml)); } } this.xml.appendChild(this.root); return this.xml; }