How to add DOCTYPE in XML using jaxp-1.2 ????

Hi all,
I know this question has been asked at least 2000 times. But I couldn't find the answer from the previously posted messages.
I would like to create a new Document (actually a XML document) and to write it out into a file. Of course, to be useful, that document needs a DTD... But I can't find a way to create that DOCTYPE tag.
In fact, I get this error: org.apache.crimson.tree.DomEx: HIERARCHY_REQUEST_ERR: This node isn't allowed there.
       at org.apache.crimson.tree.XmlDocument.appendChild(XmlDocument.java:661)
       at ServiceManager.PlaylistDOM.createDoc(PlaylistDOM.java:99)
       at ServiceManager.PlaylistDOM.load(PlaylistDOM.java:52)
       at java.lang.Thread.run(Thread.java:536)The code I have is the following:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
    //create a factory and configure it
    DocumentBuilder builder = factory.newDocumentBuilder();
    playlistDoc = builder.newDocument();
    DOMImplementation impl = builder.getDOMImplementation();
    DocumentType doctype = impl.createDocumentType(ROOT_EL, null, "playlist.dtd");
    playlistDoc = impl.createDocument(null, ROOT_EL, doctype);
catch (ParserConfigurationException pce) {}
//create the root of the XML file
Element root = (Element) playlistDoc.createElement(ROOT_EL);
root.setAttribute(FRAME_ATTR, fNb);
playlistDoc.appendChild(root);
//now print it out into XML file
TransformerFactory tfactory = TransformerFactory.newInstance();
try {
    Transformer transformer = tfactory.newTransformer();
    DOMSource source = new DOMSource(playlistDoc.getDocumentElement());
    StreamResult res = new StreamResult(new File(filename));
    transformer.transform(source, res);
catch (TransformerConfigurationException tce) {}
catch (TransformerException te) {}Thank you for your help

add both SYSTEM and PUBLIC, then you will find PUBLIC :P
================
If the doctype-public or doctype-system attributes are specified, then the html output method should output a document type declaration immediately before the first element. The name following <!DOCTYPE should be HTML or html. If the doctype-public attribute is specified, then the output method should output PUBLIC followed by the specified public identifier; if the doctype-system attribute is also specified, it should also output the specified system identifier following the public identifier. If the doctype-system attribute is specified but the doctype-public attribute is not specified, then the output method should output SYSTEM followed by the specified system identifier.
reference: http://java.sun.com/j2se/1.4.1/docs/api/javax/xml/transform/OutputKeys.html

Similar Messages

  • How to add users to OSM using UserAdmin.xsd

    Hi,
    Can you please explain me how to add users to OSM using UserAdmin.xsd i.e xml import/export tool. I need the steps how to do that..
    Thanks in Advance,
    Menaka

    Hi Razvi444,
    You need to use submit data to web service in Submit button rule,where you can use above web service.
    Refer http://office.microsoft.com/en-in/infopath-help/submit-form-data-to-a-web-service-HA010107048.aspx more details
    Thanks

  • How to add new line item using BAPI BAPI_CONTRACT_CHANGE for contract-ME32K

    HI Experts,
    how to add new line item using BAPI: BAPI_CONTRACT_CHANGE for existing contract.
    Requirement:
    Already the contract having two line items using ME31K.
    Custom program has to add new line items in existing contract.
    Thanks,
    Sendil

    I got the solution:
    We can do like this:
    1. Get all details using details, BAPI_CONTRACT_GETDETAIL.
    2. After getting results, append new line item. Then use your BAPI.
    Check this posting program.. where this bapi is used, use the same coding technique.
    IDOC_INPUT_PURCONTRACT_CHANGE

  • How to add rows in tableview using javascipt

    Hi
    I had tableview and button in my page.If i click on the button one new row should be appended to the existing tableview.
    so , how to add rows in tableview using javascipt which are editable?
    Regards,
    Pydi.

    Hi,
      Javascript is client scripting language, which is mainly used for validations at the client side.
      To add new row using a HTMLB tag ucannot use javascript. Instead pass "visibleRowCount" variable to a abap variable and add the variable on every button click.. that wil increase the visible row count.
    Also the size of the table view is the size of the itnernal table, so append a blank like to the internal table or insert it at the top.
    If you are not using HTMLB tags and using simple HTML tags u can always add a row using java script.
    Regards
    Imran.

  • How to add iview to role using webdynpro

    Hi every one, Can you please tell me how to add iview to role using webdynpro code.
    Thanks
    TK

    Hi,
    could you copy / past your code ?
    if you need help on webdynpro and your beginner, try to watch the video on internet of WebBProfessor. It's really good videos !
    regards
    Fred

  • How to add warning message while using 'print' function in Adobe LiveCycle Designer

    I am trying to make pdf document for my company which requires adding a warning message while anyone use 'print' function from the page...
    Does anyone know how to add warning message on LiveCycle Designer
    Also my supervisor mentioned something using 'nag' if that rings any bell

    No you shoudl never go into the XML source unless uinstricted to do so.
    You can open the script editor (under the window menu). It will appear above the drawing area but below the toolbars. You can resize it if there is not enough room. When you click on an object in the form you can choose an event to script against in the Show dropdown. In your case you will want to choose the prePrint event. A line will show up that indicates the object that is associated with the script as well as the event and other information. Add your script below this line. Once that is done you are finished and your form is ready for testing.
    Paul

  • How to add prefixes to xml output?

    Does anyone know a quick and easy way to add a namespace prefix to an xml document when you output it as a string?
    i'm looking for somethinglike this.
    <Order xmlns="http://www.something.com/name">
       <item>sink</item>
    <Order>
    converted into
    <dof:Order xmlns:dof="http://www.something.com/name">
       <dof:item>sink</dof:item>
    <dof:Order>
    I have attempted to use the xmlText method on the XmlObject class passing in an XmlOptions object with setSaveSuggestedPrefixes() set to my hsahmap with the namespace and prefix, however nothing happens. Well, sometimes it works and other times it does not.
    It seems that it works when i programatically build my xml using XmlObject methods, but it fails when i parse an existing xml string into the XmlObject using parse(String).
    Any help would be appreciated. I can't find any detailed help anywhere.
    Thanks
    Jeremy

    You can achieve your requirement using XSLT maaping on XML. Read more about XSLT mapping. Also read more about WordML processing tool by Microsoft.

  • How to add dropdown in excel using java?

    First of all sorry for creating new topic... i searched for it but i couldn't get it...
    Guys do you have any idea on how to add drop down in excel using Andy Khan's JExcel API? Or is there any other way?

    Sounds like a question for Andy Khan or the JExcel forum.

  • How to convert to ' ' in xml using xsl.

    Hi all,
    I have a string downloaded which has the following string
    String= text1 <I> text2 </I&it;
    I have italics tag in my xml file. But my browser does not identifies italics. So i decided to comment out italics tag in my xml using xsl
    So what i need is
    String = text1 <!--I-->text2<!--I-->
    basically to comment out italics tag alone.
    How can i replace <I> to <!--I-->?
    Is there any way in xsl to do the above in a string?
    or
    Any other ways where i can just remove <I> in my out xml file using xsl?
    Thanks in advance.
    Menaga.

    Hi,
    The ultimate solution would be that you also install also a cocoon server (http://cocoon.apache.org/), but that might be overkill.
    Have a look at /people/sap.user72/blog/2004/11/10/bsphowto-generate-pdf-output-from-a-bsp for detailed info on creating PDF from BSP.
    If you want to use XSL(-FO), you might have a look at things like http://alt-soft.com/products_xml2pdf.jsp to be called as external command.
    Eddy

  • How to add link in subtabLayout using OA Framework page personlization

    Hi,
    how to add new link in subTabLayout using OA Framework page personalization.

    Hi Sumit,
    I am also working similar kind of requirement. In my case I tried to add new tab subtab using personalization , how ever the add new item button is not enable.
    So I created new stacklayout and tried to add this to new tab in the existing subtablayout by using co process form request code:
    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processRequest(oapagecontext, oawebbean);
    OracleCallableStatement oraclecallablestatement = null;
    OracleConnection oracleconnection = (OracleConnection)oapagecontext.getApplicationModule(oawebbean).getOADBTransaction().getJdbcConnection();
    try{
    oracleconnection.setAutoCommit(true);
    oraclecallablestatement = (OracleCallableStatement)oracleconnection.prepareCall("begin GLO_TMPVIJ_PRCV(:1); end;");
    oraclecallablestatement.setString(1,"In the custom co process request");
    oraclecallablestatement.execute();
    }catch(SQLException sqlexception)
    throw OAException.wrapperException(sqlexception);
    OASubTabLayoutBean subTabLayout =
    (OASubTabLayoutBean)oawebbean.findChildRecursive("ApplicationDetsTabLayout");
    OASubTabBarBean subtabbar = (OASubTabBarBean)oawebbean.findIndexedChildRecursive("subTabBar");
    OALinkBean link = (OALinkBean)oapagecontext.getWebBeanFactory().createWebBean(oapagecontext,
    OAWebBeanConstants.LINK_BEAN, null,
    "link");
    OAStackLayoutBean commentsRN =
    (OAStackLayoutBean)oapagecontext.getWebBeanFactory().createWebBean(oapagecontext,
    "/xxhr/oracle/apps/irc/candidateManagement/webui/CommentsRn",
    "CommentsRn", // always specify name
    true); // region created in Oracle9i JDeveloper OA Extension
    subTabLayout.addIndexedChild(commentsRN);
    subTabLayout.addIndexedChild(link);
    in this I am not ale to add the new tab.
    Regards,
    Vijay Reddy.

  • How to add a 'stoke path' using 'pen tool' on CS6 (mac)?

    I'm a beginner at photoshop and I'm only 14 years old. I need to know this for my GCSE project.
    I'm trying to create something similar to this:
    Using pen tool and stroke path, but when i use the pen tool I'm not sure how to add the stroke path like that.
    I've used CS4 previously at school and when you right clicked on the path it came up with this:
    I haven't a clue how to get that up on CS6 (on mac) and when you right click it, it just seems to continue adding the path. Any help?

    In addition to conroys advice here is a video tutorial that might help you as well:
    enjoy,
    janelle

  • How to add a Cipher Suite using RSA 1024 algorithm to the 'SSL Cipher Suite Order' GPO

    Following a VA test the Default Domain GPO has been set to enable the SSL Cipher Suite Order.  Following the change Symantec Endpoint Protection Manager doesn't work properly as the the Home, Monitors and Reports pages are blank and an Schannel error is
    logged in the SEPM server's event log.
    I have spoken to Symantec and I have been told that we need to allow the RSA 1024 bit algorithm but they can't tell me which cipher suite this would be.  I have looked in the GPO setting and can't see an RSA 1024 suite but have found some in this article:
    http://tools.ietf.org/html/draft-ietf-tls-56-bit-ciphersuites-01
    I want to know how to add an additional cipher suite into the setting safely.  Am I able to just add the suite into the GPO setting (eg TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA) or do I need to do anything else beforehand?
    If anyone has any advice regarding this or cipher suite orders and troubleshooting SSL problems it would be much appreciated,
    Thanks
    Chris

    Hi Chris,
    Based on my research, RSA_EXPORT1024_DES_CBC_SHA is a previous cipher suite, which is supported, you can enable it use
    SSL Cipher Suite Order policy setting under Administrative Templates\Network\SSL Configuration Settings.
    More information for you:
    TLS/SSL Cryptographic Enhancements
    http://technet.microsoft.com/en-us/library/cc766285(v=WS.10).aspx
    Best Regards,
    Amy

  • How to add system to login using sid adm user in HANA Studio

    Hi,
    I have added SYSTEM user for my TEST system in HANA Studio. Now, I would like to add TEST system but using <sid>adm user.
    It shows "The system cannot be reached. The logon data could not be used. Do you want to add the system anyway?".
    May I know how to add TEST system using <sid>adm user?
    Thank you.
    regards,
    zl

    You need Database user, not operating system user <sid>adm user.

  • How to add doctype when generating XML from an arbitrary data structure

    I was reading SUN's tutorial "Working with XML - PART IV: Using XSLT". Inside this tutorial, in 3, it talks about how to generate XML from an arbitrary data structure making use of a XMLReader and a Transformer. The example only shows adding elements. Is there a way to add DTD information in the XML generated, i.e. <!DOCTYPE ... >? What APIs can I use?
    Thanks,
    Alex

    The simplest way seems to me is to use a XSL file for that. The <xsl:output> attributes doctype-system and doctype-public generate the DTD declaration <!DOCTYPE YOUR_ROOT SYSTEM "yourDTDfile.dtd"> and <!DOCTYPE YOUR_ROOT PUBLIC "yourDTDfile.dtd">, respectively.
    When calling transformerInstance.transform() the XSLT processor performs the identity transformation - it just copies elements, attributes, content, processing instructions and comments to the result stream.
    If you're using an xsl file for your transformation already, simply add <xsl:output doctype-system="yourDTDfile.dtd"/> to your existing XSL file.
    If you're only using the identity transformation you'd need to change the line of code where you obtain the transformer instance from the TransformerFactory to:
    t_factory.newTransformer(new StreamSource("test.xsl"));
    and use this as test.xsl:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output doctype-system="yourDTDfile.dtd"/>
       <!-- this is the identity transformation -->
       <xsl:template match="*|@*|comment()|processing-instruction()|text()">
          <xsl:copy>
             <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>Good luck.

  • How to retrieve information from XML using servlets

    Hi
    I have a scenario like this
    File-->XI-->J2ee application(HTTP Receiver adapter)
    I want to know how XI sends xml file as a query string file name?
    What ever may be the case i just need to retrieve the information from Request object and display the same in browser(JSP).How to do that, I am totally confused, please anyone help me!
    Code help is highly rewarded.
    Thanx

    Hi Rajesh!
    I have tried your code. But some where i went wrong. Please correct me: I am using NWDS2.0.9
    my web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                             "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <display-name>WEB APP</display-name>
        <description>WEB APP description</description>
        <servlet>
            <servlet-name>DisplayRes</servlet-name>
            <servlet-class>com.quinnox.DisplayRes</servlet-class>
        </servlet>
        <servlet-mapping>
              <servlet-name>DisplayRes</servlet-name>
              <url-pattern>/DisplayRes/*</url-pattern>
         </servlet-mapping>
    </web-app>
    my application.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
                                 "http://java.sun.com/dtd/application_1_3.dtd">
    <application>
        <display-name>ReceiverEntpr</display-name>
        <description>EAR description</description>
        <module>
            <web>
                <web-uri>HttpReceiver.war</web-uri>
                <context-root>/HttpReceiver</context-root>
            </web>
        </module>
    </application>
    and my servlet code:
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.io.Writer;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.xml.sax.EntityResolver;
    import org.xml.sax.SAXException;
    import com.sun.java_cup.internal.parser;
    import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException
              doWork(requset, response);
         public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
              doWork(req, resp);
         private void doWork(HttpServletRequest req, HttpServletResponse resp) throws IOException
              String path = null;
              PrintWriter out = null;
              PrintWriter p2=resp.getWriter();     
              try
                   resp.setContentType("text/xml");
                   out = resp.getWriter();
                   out.println("hi");
                   path = req.getPathInfo();
                   if(req.getContentLength() != -1){
                   outputURI(req.getInputStream(), out);
              } catch (IOException ioe) {     return;     
         //private void outputURI(InputStream resultStream, Writer out) {
              private void outputURI(InputStream resultStream, PrintWriter out) {
              if (resultStream == null) {
    //             no default file
    //            logger.error("No File to return");
              return;
              try {
              DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    //            Class clazz = loader.loadClass("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
    //            DocumentBuilderFactoryImpl factory = (DocumentBuilderFactoryImpl) clazz.newInstance();
    //            DocumentBuilder parser = factory.newDocumentBuilder();
              parser.setEntityResolver(new ClassPathEntityResolver());
              printXML(parser.parse(resultStream), out);
              resultStream.close();
              } catch (Exception e) {
    //            logger.error("Trying to parse the output " , e);
         //private void printXML(Document document, Writer writer) throws Exception {
              private void printXML(Document document, PrintWriter writer) throws Exception {
              Transformer transformer = TransformerFactory.newInstance().newTransformer();
              Source source = new DOMSource(document);
              Result output = new StreamResult(System.out);
              transformer.transform(source, output);
    //             Write as XML so that entity references can be resolved.
              if (writer != null) {
              transformer.transform(source, new StreamResult(writer));
    Please tell me how to display in servlet.
    If it is better to display in a browser. Please send me the code.
    Thanks

Maybe you are looking for

  • ABAP Report Performance Problem

    Hello Experts, Check the folowing code and suggest me a solution. IF BSIS-BLART = 'KR'. SELECT SINGLE LIFNR  AS LIFNR2   FROM BSAK  INTO CORRESPONDING FIELDS OF ITAB WHERE  BELNR = ITAB-BELNR AND GJAHR = ITAB-GJAHR. SELECT SINGLE NAME1 AS NAME2 FROM

  • DAQmx- create channel- no channels found

    Hello, i am new to labview. So maybe my question is easy... I want to generate a signal. That's why i am using the DAQmx-create channel.vi . I i created a control to chose the channel, where the signal is generated. But no channels are found. i am us

  • Size of photo's to large

    When i receive mail with enclosed photo's then the photo's are displayed in a large size. Is it possible for me to change that? Thanks in advance, René Haagsma

  • Sharing photos by e-mail arranged by version name

    I need to send all photos in one project from Aperture by e-mail arranged by version name. That is, all photos in the letter must be ordered by version name. When i use Share button Aperture generates an e-mail where the photos are mixed. Does anyone

  • Does CRM supports firefox and other browsers apart from IE

    Hi, can you pls share if CRM supports firefox and other browsers apart from IE. are their any specific settings to enable other browsers? any documentation would be helpful. thanks RH