[JBoss] getElementsByTagName doesn't seem to be working in java on jboss 6

Discussão em 'StackOverflow' iniciado por Stack, Julho 21, 2021.

  1. Stack

    Stack Membro Participativo

    We are migrating applications from JBoss 3.0.8 to 6.1.0. one of the application uses org.w3c.dom packages to deal with xml files. I have this xml

    <root><data><head1>test1</head1></data><data><head2>test2</head2></data><data><head3>test3</head3></data></root>


    java code:

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new File("test.xml"));
    DOMResult domResult = new DOMResult(doc);
    Element root = doc.getDocumentElement();
    NodeList nodelist = root.getElementsByTagName("data");
    System.out.println("nodelist length : "+nodelist.getLength());
    for (int i = 0; i < nodelist.getLength(); i++) {
    Element node = (Element) nodelist.item(i);
    String fullPathName = "result"+i+".xml";
    FileOutputStream fout = new FileOutputStream(fullPathName);

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty(OutputKeys.ENCODING, "us-ascii");
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"no");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.transform(new DOMSource(node), new StreamResult(fout));
    }


    this code does split content into multiple files but does not work in jboss 6. seems like getElementsByTagName is not working on jboss 6. it copies whole original content into all the split files.

    Result xml in all files

    <root><data><head1>test1</head1></data><data><head2>test2</head2></data><data><head3>test3</head3></data></root>


    Any help appreciated.

    Continue reading...

Compartilhe esta Página