DTD to java

i need to write a model class for a dtd file, that is, read a dtd and model it into fields in,say, a java object. Is there an easy way to do it?

Hi,
you might want to check JAXB ( [https://jaxb.dev.java.net/|https://jaxb.dev.java.net/] ), which supports XML schema, but also DTD. It is used to create Java classes from an XML schema or DTD, which also contain code to marshal or unmarshal an XML document to Java classes or vice versa.
JAXB (package javax.xml.bind) ist part of Java SE 6.0. In prior versions, it was shipped separately or as part of the web service tools.
Martin
PS: after reading your post a second time I see, that you do not want to create classes out of a DTD, but objects which contain a description of the classes! That's not the intention of JAXB.
However the developers of JAXB had to do the same when they wrote the JAXB DTD compiler. So perhaps you get some ideas if you look for the source code of the reference implementation of the JAXB compiler.
Edited by: martin@work on Jun 16, 2008 9:27 AM

Similar Messages

  • Creating an XML document from a DTD in Java

    Hi All,
    I need help on the following requirement very badly. Pls help me.
    I have a requirement to implement with java and XML. I am quit new to XML.Can any of you pls help me.
    I have a DTD file. I need to generate XML document from it using java code. I have to use DTD as a template to generate my XML document.
    After going through WEB sites, I understtod that, we have to user Java API JAXB for my requirement. But I could not find JAXB.jar anywhere.
    I need to know the following inforamtion ....
    1. Is my understanding of using JAXB for my requirement is correct?
    2. Where can I get JAXB.jar?
    3. What are the steps to create XML document from a DTD in Java?
    If can give me a sample code for this would help me a lot.
    Pls pls reply me. Your help is greatly appreciated.
    Thanks in Advance.
    Regards,
    Gayathri.

    hi Gayathri,
    iam currently working in the same field.
    firs download jaxb from this link:
    http://java.sun.com/xml/downloads/jaxb.html
    first u need to marshall it.
    cheers
    shashi

  • Convert XML file into DTD using Java

    Hi All,
    I want to do convert the xml file into DTD using Java.
    I read the DOM package but didnt get clear idea.
    Anyone of you have an idea please share the coding with me.
    Any suggestions greatly appreciated.
    Thanks
    Veera

    Hi All,
    I want to do convert the xml file into DTD using Java.
    I read the DOM package but didnt get clear idea.
    Anyone of you have an idea please share the coding with me.
    Any suggestions greatly appreciated.
    Thanks
    Veera

  • How to parse a DTD using java

    Hi all,
    I want to parse a DTD using java. I need to get elemnets and attibutes in the DTD file in their correct order.
    What are the I nedd to download for this?
    Could anyone please help me to solve this issue.
    Please do favour with me.
    Thanks and reagrds,
    Sreekanth

    You are welcome to parse a DTD in java, but you cannot do it with the XML tools, since a DTD does not follow the rules of XML. (That is one of the advantages of a Schema.)
    Although it is not XML, it certainly has repeatable patterns and delimeters, so all is not lost. I'd suggest you read about Pattern, and Matcher objects and learn about regular expressions.
    Dave Patterson

  • XML validation with DTD in java 1.5 not supporting

    Hi,
    I am facing a problem regarding validation of xml file with DTD tag in it.
    I have disabled the parser through setValidating(false) method.
    xml file is not parsed in JRE 1.5.but it is parsed in JRE 1.6.
    Why this is showing such a behavior?
    I have used xerces 2.9.0,xml-api.jar and other jar regarding XML api but still it is giving error.
    please help me.
    please provide a jar file name or its issue resolution in jre 1.5 or 1.4.

    thanks for your prompt reply.
    I required that it should be completely disabled in jre 1.5(jdk1.5 or 1.4).
    I am using DOM Parsing.I have currently disabled with follwowing method,
    builderFactory.setValidating(false);
    builderFactory.setFeature("http://xml.org/sax/features/validation",
         false);
         builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
         builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
         builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
         builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
         factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    in 1.6 it is working fine but I required that i have to disabled it.but it is giving a error in jre1.5.
    Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
    I just want to disable the parsing in jdk version 1.5 or 1.4
    thanks in advance
    anand

  • DTD Creation using Java from XMLSchema

    Dear Friends
    Can anybody solve my problem.See friends i have the Schema With the help of that schema i want to create DTD Using Java .If u peoples have any solution please forward me sample code or tell me where i can get the information.

    your best bet is open up a String object and create dtd according to schema,u probably have to hard code allots....or post your schema here...

  • Java and DTD

    Good morning.
    Is there any way to enter and move through an dtd with java?

    The method 'getDocType()' of the 'Document' class return a 'DocType' object.
    This object represents the doctype associated to the xml. This is OK.
    However, this object will not let me travel for the nodes of DTD

  • How to generate XML from relational data : PL/SQL or Java

    I'm new to Oracle XML and would appreciate some advice. I've been asked to generate XML documents from data stored in relational tables. The XML documents must be validated against a DTD. We will probably want to store the XML in the database.
    I've seen a PL/SQL based approach as follows :
    1.Mimic the structure of the DTD using SQL object types 2.Assign the relational data to the object type using PL/SQL as required
    3.Use the SYS_XMLGEN package to render the required XML documents from the SQL objects
    However, creating the object types seems to be quite time consuming (step 1 above) for anything other than the simplest of XML documents.
    I've also seen that there is the Java based approach, namely :
    1. Use the XML generator to build Java classes based on a DTD.
    2. Use these classes to build the required XML
    On the face of it, the Java based approach seems simpler. However, I'm not that familiar with Java.
    Which is the best way to proceed ? Is the PL/SQL based approach worth pursuing or should I bite the bullet and brush up my Java ?
    Is it possible to use a combination of PL/SQL and Java to populate the dtd generated java classes (step 2 of the Java approach) to reduce my learning curve ?
    Thanks in advance

    To help answer your questions:
    1) Now, in 9iR2, you can use SQL/XML as another choice.
    2) You can also use XSU to generate the XML and use XSLT to transform it to a desired format instead of using object views if possible.
    3) XDK provide Class generator support to populate XML data to Java classes.

  • Can't convert oracle.xml.parser.DTD to oracle.xml.parser.v2.DTD.

    I am getting the following Error while trying
    to compile the SampleMain.java file(Generating an XML document from a given Employee.dtd).
    I have set my classpath to use xmlparser.jar.
    D:\XMls>javac SampleMain.java
    SampleMain.java:65: Can't convert oracle.xml.parser.DTD to oracle.xml.parser.v2.DTD.
    main(java.l
    ang.String[]).
    generator.generate(dtd, doctype_name);

    Would you check the java parser version you are using? If using java parser V2, the normal lib name is xmlparserv2.jar.
    null

  • Parsing XML with invalid URI for DTD

    When parsing an XML file (with aelfred2) I get the following error:
    Exception in thread "main" gnu.xml.dom.ls.DomLSException: Absolute URL required with null context: CQCGWProtocol.DTD
    at gnu.xml.dom.ls.DomLSParser.doParse(libgcj.so.7)
    at gnu.xml.dom.ls.DomLSParser.parse(libgcj.so.7)
    at gnu.xml.dom.DomDocumentBuilder.parse(libgcj.so.7)
    at CQC.main(CQC.java:44)
    Caused by: java.net.MalformedURLException: Absolute URL required with null context: CQCGWProtocol.DTD
    at java.net.URL.<init>(libgcj.so.7)
    at java.net.URL.<init>(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.pushURL(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.parseDoctypedecl(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.parseProlog(libgcj.so.7)
    at gnu.xml.aelfred2.XmlParser.parseDocument(libgcj.so.7)
    I'm puzzled, as I have disabled validation:
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setIgnoringComments(true);
    domFactory.setNamespaceAware(false);
    domFactory.setValidating(false);
    My goal is to have the parser ignore the DOCTYPE tag and not try to find the DTD. Can someone suggest how you turn this off - apparently, setting the validation to false is not the right approach.
    I'm running Java 1.4.2 on Fidora Core 5.
    Thanks for suggestions!

    Create an org.xml.sax.EntityResolver and apply it to your parser. The API documentation for the interface has an example of how to write one.
    And no, turning of validation doesn't turn off processing of DTDs because DTDs are for things other than validation. Entity replacement, for example.

  • External DTDs in 1.1

    Can 1.1 on Win2000 Server handler DTD that are external to the xml document? I know it handles local DTDs.
    Here is the decl:
    <!DOCTYPE TRANSCRIPT SYSTEM "\\dga22\DTDs\transcript.dtd">
    Here is the error.
    Thu Mar 08 15:51:40 CST 2001: \Transcription\Inprocess\trans02022001T1.xml:
    oracle.ifs.common.IfsException: IFS-12608: Error while pre-parsing with the SAXParser: at line (2), column (59): Error opening external DTD '\\dga22\DTDs\transcript.dtd'.
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at oracle.ifs.common.IfsException.<init>(Compiled Code)
    at oracle.ifs.common.IfsException.<init>(Compiled Code)
    at oracle.ifs.beans.parsers.IfsXmlParser.preParse(Compiled Code)
    at oracle.ifs.beans.parsers.IfsXmlParser.getParserName(IfsXmlParser.java:367)
    at oracle.ifs.beans.parsers.IfsXmlParser.parse(IfsXmlParser.java:276)
    at oracle.ifs.beans.parsers.IfsXmlParser.parse(IfsXmlParser.java:214)
    at oracle.ifs.utils.common.ParserHelper.parseExistingDocument(ParserHelper.java:379)
    at oracle.ifs.protocols.ntfs.server.FileProxy.parseFile(FileProxy.java:785)
    at oracle.ifs.protocols.ntfs.server.FileProxy.cleanupFile(Compiled Code)
    at oracle.ifs.protocols.ntfs.server.FileProxy.run(Compiled Code)
    null

    I think the DTD has to be stored in the IFS repository or accessed with an HTTP protocol
    null

  • Sun Java System Web Proxy Server (4.0.2) - manage server will not start

    In short here's the scenario and main problem.   
    a. Proxy admin server start - no problem
    b. Create a new manage server (no proxying - just testing it) using different port. It just won't start. No logs produced either.
    Here's the server.xml for the new manage server.
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
       Copyright (c) 2003 Sun Microsystems, Inc.  All rights reserved.
       Use is subject to license terms.
    -->
    <!DOCTYPE SERVER PUBLIC "-//Sun Microsystems Inc.//DTD Sun Java System Web Proxy Server 4.0//EN" "file:///E:/Sun/ProxyServer40/bin/proxy/dtds/sun-web-proxy-server_4_0.dtd">
    <SERVER>
        <PROPERTY name="accesslog" value="E:/Sun/ProxyServer40/proxy-server3/logs/access"/>
        <LS id="ls1" port="8083" servername="cbaob-b3-csddb1.adp1.cibc.pte"/>
        <MIME id="mime1" file="mime.types"/>
        <ACLFILE id="acl1" file="E:/Sun/ProxyServer40/httpacl/generated.proxy-server3.acl"/>
        <USERDB id="default"/>
        <FILECACHE enabled="true"  maxage="30" mediumfilesizelimit="537600" mediumfilespace="10485760" smallfilesizelimit="2048" smallfilespace="1048576" transmitfile="false" maxfiles="1024" hashinitsize="0"/>
        <CACHE enabled="true" cachecapacity="2000" cachedir="E:/Sun/ProxyServer40/proxy-server3/cache">
            <PARTITION  partitionname="part1" partitiondir="E:/Sun/ProxyServer40/proxy-server3/cache" maxsize="100" minspace="5" enabled="true"/>
    <GC enabled="true" gchimargin="80" gclomargin="70" gcleavefsfull="60" gcextramargin="30"/>
        </CACHE>
        <LOG file="E:/Sun/ProxyServer40/proxy-server3/logs/errors" loglevel="finest"/>
    </SERVER>
    Nothing seems to be wrong with this. The XML format follows the specified DTD.   
    Would appreciate any help.   
    Thanks.

    Thanks for your reply. Yes. This is really odd.
    Anyway to make the whole story short, i uninstall this proxy server 4.0.2 on this server (say server1) and try to reinstall a new proxy 4.0.13 but having odd problem (i have administration rights)
    Here it goes.
    a. CMD java -version is 1.4.2_XX
    b. Double click the proxy 4.0.13 setup.exe - nothing happen.
    c. CMD setup --javahome c:\jdk1.6_XX - nothing happen
    Here retrying.
    a. Login to server2 and map conection to server1
    b. Double click the proxy 4.0.13 setup.exe on server1 (while on server2) - setup.exe runs. This proves the proxy setup.exe on server1 is good.
    c. Make a copy of proxy 4.0.13 on server2
    d. Login to server1 and map connection to server2
    e. Double click the proxy 4.0.13 setup.exe on server2 (while on server1) - setup.exe did not run.
    Both servers are on the same domain and i'm using same ID to access both servers
    Again, no logs on the windows events (security, application, system)
    This is becoming mind a boggling mystery.
    Any idea what's going on?
    Thanks.

  • Trouble parsing DTD

    I'm trying to parse a DTD with Java using the code below. Using the XMLParser the parsing works fine, but when I try to use the DOMParser nothing works, I end up with the errors like
    "XML-0230: (Error) Illegal change of encoding: from UCS-2 to Unicode.
    XML-0192: (Fatal Error) Unexpected text in DTD."
    I've tried to change the encoding and remove the "unexpected" text, but I always end up with another error.
    I could use the XMLParser, but when I try to generate classes with the oracle.xml.classgen.ClassGenerator, the method generator.generate(dtd, doctype_name) requires the dtd to be of type oracle.xml.parser.v2.DTD whilst the xmlParser.getDoctype() returns a DTD of type oracle.xml.parser.DTD. I don't understand how to convert one type to the other.
    Even worse, if I change the DTD the slightest, i e remove one single comment, the parsing fails. The parser starts complaining of illegal change of encoding.
    I'm posting a small snippet of the DTD. This snippet is hasn't been possible to parse for me due to all the errors. However, if I parse the whole DTD with the XMLParser it works fine. The whole DTD is too big to post.
    Java code:
    oracle.xml.parser.XMLParser xmlParser = new XMLParser();
    xmlParser.parseDTD(fileToURL(dtdFile), rootName);
    oracle.xml.parser.v2.DOMParser DOMParser domParser = new DOMParser();
    domParser.setDebugMode(true);
    domParser.setErrorStream(System.out);
    domParser.setValidationMode(false);
    domParser.parseDTD(fileToURL(dtdFile), rootName);
    oracle.xml.parser.v2.DTD dtd_v2 =(oracle.xml.parser.v2.DTD)domParser.getDoctype();
    oracle.xml.parser.DTD dtd_v1 = (oracle.xml.parser.DTD)xmlParser.getDoctype();
    DTD file:
    <?xml version="1.0" encoding="Unicode"?>
    <!DOCTYPE DMP_xml_defs [
    <!ELEMENT CompanyQuery CompEmployees CDATA>
    <!ATTLIST CompanyQuery Employees CDATA>
    <!ATTLIST CompanyQuery CompTurnover CDATA>
    <!ATTLIST CompanyQuery SNI CDATA>
    <!ATTLIST CompanyQuery SNILevel (1|2|3|4|5|6|)
    <!ATTLIST CompanyQuery Heading CDATA>
    <!ATTLIST CompanyQuery CompType CDATA>
    ]>

    A DTD file is not an XML file, and not amenable to parsing with an XML parser. Parse a DTD with a DTD parser.
    Wutka DTD Parser:http://www.wutka.com/dtdparser.html

  • XML and DTD parsing

    How do I validate an xml file using a dtd in Java? Is there a parser that validates xml's against dtd's?
    I have parsed the xml file that contains the DOCTYPE necessary to define the dtd. However, the parser only seems to check whether or not the dtd exists but doesn't bother to check whether the xml file is valid given the specified dtd?
    I am using the jaxp parser.
    Kind Regards,
    Fadi

    Take a look at the xerces parser (http://xml.apache.org/).
    --Arnout                                                                                                                                                                                           

  • OC4J and Local (system) XML DTD files

    I am in a situation where I am deploying a web application to an instance of 10.1.2 that is on a public-facing box that does not have the ability to access the outside world via the web due to security restrictions.
    When I start the application, I'm getting connection refused errors because the XML parser is trying its hardest to validate the XML files for Spring and MyFaces by remotely fetching the DTD file. Is there a way I can get the application to read a local copy of the DTD without having to hard code a full path to the file?
    I've tried changing the doctype declaration for MyFaces to look like this:
    <!DOCTYPE faces-config SYSTEM "web-facesconfig_1_0.dtd">And I put the DTD in the same directory as the XML configuration file (in the WEB-INF directory). Eclipse seems to like that ok, but when I deploy that to 10.1.2, I get the following exception:
    javax.faces.FacesException: java.net.MalformedURLException: no protocol: web-facesconfig_1_0.dtd
         at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:123)
         at org.apache.myfaces.webapp.StartupServletContextListener.initFaces(StartupServletContextListener.java:63)
         at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:46)
         at com.evermind.server.http.HttpApplication.initDynamic(HttpApplication.java:1009)
         at com.evermind.server.http.HttpApplication.<init>(HttpApplication.java:549)
         at com.evermind.server.Application.getHttpApplication(Application.java:890)
         at com.evermind.server.http.HttpServer.getHttpApplication(HttpServer.java:707)
         at com.evermind.server.http.HttpSite.initApplications(HttpSite.java:625)
         at com.evermind.server.http.HttpSite.setConfig(HttpSite.java:278)
         at com.evermind.server.http.HttpServer.setSites(HttpServer.java:278)
         at com.evermind.server.http.HttpServer.setConfig(HttpServer.java:179)
         at com.evermind.server.ApplicationServer.initializeHttp(ApplicationServer.java:2394)
         at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:1551)
         at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:92)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: java.net.MalformedURLException: no protocol: web-facesconfig_1_0.dtd
         at java.net.URL.<init>(URL.java:567)
         at java.net.URL.<init>(URL.java:464)
         at java.net.URL.<init>(URL.java:413)
         at oracle.xml.parser.v2.NonValidatingParser.pushExternalDTD(NonValidatingParser.java:543)
         at oracle.xml.parser.v2.NonValidatingParser.parseDoctypeDecl(NonValidatingParser.java:468)
         at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:301)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:280)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:196)
         at org.apache.commons.digester.Digester.parse(Digester.java:1548)
         at org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl.getFacesConfig(DigesterFacesConfigUnmarshallerImpl.java:183)
         at org.apache.myfaces.config.FacesConfigurator.feedWebAppConfig(FacesConfigurator.java:387)
         at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:120)
         ... 14 moreI've tried variations like ./filename.dtd and ../filename.dtd to no avail. I'm sure I'm missing something fundamental here, but how can I get OC4J to read my local DTD?
    Thanks in advance!

    Avi, you're right, the parser is indeed wanting a real URL. So here's what I've done. I replaced the dtd filename with the complete path to the file, so it looks like this:
    <pre>
    <!DOCTYPE faces-config SYSTEM "file:///C:/path/to/dtd/web-facesconfig_1_0.dtd">
    </pre>
    I deployed, started the app, and it worked. This doesn't really feel like the right solution, however, because I'm going to have to rely on a hardcoded file location for the DTD on our production server. If our admins change that, then I'm out of luck and would have to redeploy the application. Does anyone know if there is a way to get this to be more relative?
    One idea that someone gave me was to put the DTD files in a web-accessible location in the application and reference via http:// instead of file://. At least that way I wouldn't be dependent on the file system. I'd still have to hardcode a URL so I couldn't use the same files for all our development environments, but it might be a slightly cleaner solution. Another possible (yet really ugly) solution is to inline the DTD's in the XML file.
    Asanka, I'm not quite sure I follow what you said. Where would I put such code to use Xerxes? In a servlet loaded on init?
    Thanks for the help so far, everyone.

Maybe you are looking for

  • No seek complete error

    I've been building basic DVDs (several tracks, no menus, no chapeter marks) for my job and I'd say 95% of the time I have no problems at all. Then the other 5% of the time the disc ejects about halfway into the burn and there is a messae in the log t

  • Problems syncing TV Shows to iPod Touch

    I am having issues syncing my TV shows that I've purchased on iTunes into my iPod Touch. I get a pop up window that says: The episode was not copied to the iPod because it cannot be played on this iPod. I just purchased this iPod yesterday, I've upda

  • Describe distance error in upgrade 7.0

    Hi , I need to add IN BYTE MODE or IN CHARACTER MODE in this line . DESCRIBE DISTANCE BETWEEN e071_rotab-ta_pgmid AND e071_rotab-trkorr INTO keylength. The keylength is of type p. Should i add byte or character ? Moderator message: Last warning, one

  • Construct Dynamic URL

    Apex 2.2.1 I'm struggling to work out best way to construct a URL dynamically. Process is: At the press of link (or button) in a multi row region I would like to call a db stored function passing in column values from the region and also items from a

  • Apple ID not changed

    A friend of mine gave me their iPhone 4 and despite having entered my Apple ID details in the settings, when I download or update applications it still prompts me for the previous user login and password. How do I update this?