简体   繁体   中英

How to add a tag to the prolog of an XML via Java

I need my XML to have the following tags, the problem is that I'm not entirely sure how to communicate the issue so google searches are not providing anything. Hopefully by seeing my question you'll understand my issue.

The beginning of the XML document that I am creating in my Java code needs to have the following in the prolog:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?AdlibExpress applanguage="USA" appversion="5.0.0" dtdversion="2.6.3" ?>
<!DOCTYPE JOBS SYSTEM "D:\Adlib5.4\System\DTD\AdlibExpress.dtd">

The encoding is easy enough. I am having difficulty adding:

<?AdlibExpress applanguage="USA" appversion="5.0.0" dtdversion="2.6.3" ?>  

I don't even know what to look for or what to call this.

Here is the library I am using

 DocumentBuilderFactory docFactory1 = DocumentBuilderFactory.newInstance();
        docFactory1.setNamespaceAware(true);

        DocumentBuilder docBuilder1 = docFactory1.newDocumentBuilder();

        // root elements
        Document doc = docBuilder1.newDocument();

Theres gotta be something in one of these classes to do what I'm talking about but I'm not having luck finding it. If you're able to help me, can you also let me know how to properly communicate the issue? Thanks

<?AdlibExpress...?> is a processing instruction .

You can create it with

doc.appendChild(
    doc.createProcessingInstruction("AdlibExpress", "applanguage=\"USA\" appversion=\"5.0.0\" dtdversion=\"2.6.3\""));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM