1 /* 2 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 3 * 4 * This software is open source. 5 * See the bottom of this file for the licence. 6 * 7 * $Id: TestDOMReader.java,v 1.2 2004/06/25 08:03:50 maartenc Exp $ 8 */ 9 10 package org.dom4j.io; 11 12 import java.io.ByteArrayInputStream; 13 import java.io.StringWriter; 14 import java.net.URL; 15 import java.util.List; 16 import javax.xml.parsers.DocumentBuilder; 17 import javax.xml.parsers.DocumentBuilderFactory; 18 import junit.framework.*; 19 import junit.textui.TestRunner; 20 import org.dom4j.AbstractTestCase; 21 import org.w3c.dom.NamedNodeMap; 22 23 /*** 24 * 25 * @author Maarten 26 */ 27 public class TestDOMReader extends AbstractTestCase { 28 29 public TestDOMReader(java.lang.String testName) { 30 super(testName); 31 } 32 33 public static void main( String[] args ) { 34 TestRunner.run( suite() ); 35 } 36 37 public static Test suite() { 38 TestSuite suite = new TestSuite(TestDOMReader.class); 39 return suite; 40 } 41 42 // TODO add test methods here, they have to start with 'test' name. 43 // for example: 44 // public void testHello() {} 45 public void testBug972737() throws Exception { 46 String xml = 47 "<schema targetNamespace='http://SharedTest.org/xsd' " + 48 " xmlns='http://www.w3.org/2001/XMLSchema' " + 49 " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" + 50 " <complexType name='AllStruct'>" + 51 " <all>" + 52 " <element name='arString' type='xsd:string'/>" + 53 " <element name='varInt' type='xsd:int'/>" + 54 " </all>" + 55 " </complexType>" + 56 "</schema>"; 57 58 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 59 DocumentBuilder builder = factory.newDocumentBuilder(); 60 org.w3c.dom.Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); 61 62 DOMReader reader = new DOMReader(); 63 org.dom4j.Document dom4jDoc = reader.read(doc); 64 65 List namespaces = dom4jDoc.getRootElement().declaredNamespaces(); 66 assertEquals(2, namespaces.size()); 67 68 System.out.println(dom4jDoc.asXML()); 69 } 70 71 } 72 73 74 75 76 /* 77 * Redistribution and use of this software and associated documentation 78 * ("Software"), with or without modification, are permitted provided 79 * that the following conditions are met: 80 * 81 * 1. Redistributions of source code must retain copyright 82 * statements and notices. Redistributions must also contain a 83 * copy of this document. 84 * 85 * 2. Redistributions in binary form must reproduce the 86 * above copyright notice, this list of conditions and the 87 * following disclaimer in the documentation and/or other 88 * materials provided with the distribution. 89 * 90 * 3. The name "DOM4J" must not be used to endorse or promote 91 * products derived from this Software without prior written 92 * permission of MetaStuff, Ltd. For written permission, 93 * please contact dom4j-info@metastuff.com. 94 * 95 * 4. Products derived from this Software may not be called "DOM4J" 96 * nor may "DOM4J" appear in their names without prior written 97 * permission of MetaStuff, Ltd. DOM4J is a registered 98 * trademark of MetaStuff, Ltd. 99 * 100 * 5. Due credit should be given to the DOM4J Project - 101 * http://www.dom4j.org 102 * 103 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 104 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 105 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 106 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 107 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 108 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 109 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 110 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 111 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 112 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 114 * OF THE POSSIBILITY OF SUCH DAMAGE. 115 * 116 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 117 * 118 * $Id: TestDOMReader.java,v 1.2 2004/06/25 08:03:50 maartenc Exp $ 119 */