Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 99420 invoked from network); 1 Dec 2003 13:46:31 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 1 Dec 2003 13:46:31 -0000 Received: (qmail 3809 invoked by uid 500); 1 Dec 2003 13:46:14 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 3768 invoked by uid 500); 1 Dec 2003 13:46:14 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 3723 invoked by uid 500); 1 Dec 2003 13:46:13 -0000 Delivered-To: apmail-ws-axis-cvs@apache.org Date: 1 Dec 2003 13:46:16 -0000 Message-ID: <20031201134616.99321.qmail@minotaur.apache.org> From: dims@apache.org To: ws-axis-cvs@apache.org Subject: cvs commit: ws-axis/java/src/org/apache/axis/utils DOM2Writer.java XMLUtils.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N dims 2003/12/01 05:46:16 Modified: java/src/org/apache/axis/utils DOM2Writer.java XMLUtils.java Log: Fix for Bug 23059 - DOM2Writer generates invalid XML (missing namespaces) from nmoyere@calendra.com (Nicolas Moy?re) Revision Changes Path 1.18 +11 -8 ws-axis/java/src/org/apache/axis/utils/DOM2Writer.java Index: DOM2Writer.java =================================================================== RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/DOM2Writer.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- DOM2Writer.java 18 Jul 2003 12:40:40 -0000 1.17 +++ DOM2Writer.java 1 Dec 2003 13:46:15 -0000 1.18 @@ -115,11 +115,12 @@ out.println("\"?>"); } NSStack namespaceStack = new NSStack(); - print(node, namespaceStack, out, pretty, 0); + print(node, namespaceStack, node, out, pretty, 0); out.flush(); } private static void print(Node node, NSStack namespaceStack, + Node startnode, PrintWriter out, boolean pretty, int indent) { @@ -143,7 +144,7 @@ for (int i = 0; i < numChildren; i++) { - print(children.item(i), namespaceStack, out, + print(children.item(i), namespaceStack, startnode, out, pretty, indent); } } @@ -185,7 +186,7 @@ if (!prefixIsDeclared) { - printNamespaceDecl(node, namespaceStack, out); + printNamespaceDecl(node, namespaceStack, startnode, out); } } @@ -221,7 +222,7 @@ if (!prefixIsDeclared) { - printNamespaceDecl(attr, namespaceStack, out); + printNamespaceDecl(attr, namespaceStack, startnode, out); } } } @@ -243,7 +244,7 @@ for (int i = 0; i < numChildren; i++) { - print(children.item(i), namespaceStack, out, pretty, + print(children.item(i), namespaceStack, startnode, out, pretty, indent + 1); } } @@ -332,6 +333,7 @@ private static void printNamespaceDecl(Node node, NSStack namespaceStack, + Node startnode, PrintWriter out) { switch (node.getNodeType()) @@ -339,13 +341,13 @@ case Node.ATTRIBUTE_NODE : { printNamespaceDecl(((Attr)node).getOwnerElement(), node, - namespaceStack, out); + namespaceStack, startnode, out); break; } case Node.ELEMENT_NODE : { - printNamespaceDecl((Element)node, node, namespaceStack, out); + printNamespaceDecl((Element)node, node, namespaceStack, startnode, out); break; } } @@ -353,6 +355,7 @@ private static void printNamespaceDecl(Element owner, Node node, NSStack namespaceStack, + Node startnode, PrintWriter out) { String namespaceURI = node.getNamespaceURI(); @@ -361,7 +364,7 @@ if (!(namespaceURI.equals(Constants.NS_URI_XMLNS) && prefix.equals("xmlns")) && !(namespaceURI.equals(Constants.NS_URI_XML) && prefix.equals("xml"))) { - if (XMLUtils.getNamespace(prefix, owner) == null) + if (XMLUtils.getNamespace(prefix, owner, startnode) == null) { out.print(" xmlns:" + prefix + "=\"" + namespaceURI + '\"'); } 1.89 +22 -4 ws-axis/java/src/org/apache/axis/utils/XMLUtils.java Index: XMLUtils.java =================================================================== RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/XMLUtils.java,v retrieving revision 1.88 retrieving revision 1.89 diff -u -r1.88 -r1.89 --- XMLUtils.java 1 Dec 2003 08:37:38 -0000 1.88 +++ XMLUtils.java 1 Dec 2003 13:46:15 -0000 1.89 @@ -507,19 +507,37 @@ return null; } - public static String getNamespace(String prefix, Node e) { + /** + * Searches for the namespace URI of the given prefix in the given DOM range. + * + * The namespace is not searched in parent of the "greaterancestor". This is + * usefull to get all the needed namespaces when you need to ouput only a + * subtree of a DOM document. + * + * @param prefix the prefix to find + * @param e the starting node + * @param greaterancestor null to search in all the document or a parent node where the search must stop. + * @return null if no namespace is found, or the namespace URI. + */ + public static String getNamespace(String prefix, Node e, Node greaterancestor) { while (e != null && (e.getNodeType() == Node.ELEMENT_NODE)) { Attr attr = null; if (prefix == null) { - attr = ((Element)e).getAttributeNode("xmlns"); + attr = ((Element) e).getAttributeNode("xmlns"); } else { - attr = ((Element)e).getAttributeNodeNS(Constants.NS_URI_XMLNS, - prefix); + attr = ((Element) e).getAttributeNodeNS(Constants.NS_URI_XMLNS, + prefix); } if (attr != null) return attr.getValue(); + if (e == greaterancestor) + return null; e = e.getParentNode(); } return null; + } + + public static String getNamespace(String prefix, Node e) { + return getNamespace(prefix, e, null); } /**