DOMReaderTest xref

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