« Return to Thread: XMLOutputter not outputting inline DTD

Re: XMLOutputter not outputting inline DTD

by ashok403 :: Rate this Message:

Reply to Author | View in Thread

More Info
Code to test this
<code>
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;

// xml file name mbean-definitions.xml
public class UpdateXMLFile {

        public static void main(String[] args) {
                String xQuery = "/mbean-definitions/mbean[@name='user']/attribute[@name='username']/validation-info/pattern";
                File inputXMLFIle = new File("src\\mbean-definitions.xml");
                File outputXMLFIle = new File("src\\mbean-definitions_output.xml");
                SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
                try {
                        Document document =  saxBuilder.build(inputXMLFIle);
                        DocType docType = document.getDocType();
                        System.out.println(docType.getDocument().getContent());
                        Element pattern = (Element)XPath.selectSingleNode(document, xQuery);
                        System.out.println("initial pattern is :"+ pattern.getTextTrim());
                        pattern.setText("^[\\w_]{9,29}$");
                        XMLOutputter xmlOutput = new XMLOutputter();
                        xmlOutput.output(document, new FileOutputStream(outputXMLFIle));
                } catch (JDOMException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                       
                        e.printStackTrace();
                }
               
               
               
        }
}

</code>
ashok403 wrote:
Hi,
I am using JDOM, Xpath to query and update my XML file. Everything is working fine but the Schema definition is missing from DOCTYPE tag in output file. In my XML i have Schema specified in line as shown in attached file.

mbean-definitions.xml

 « Return to Thread: XMLOutputter not outputting inline DTD