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                                                                                                                                                                                           

Similar Messages

  • Xml and DTD parser in oracle

    I have to parse a validated xml message into oracle database tables.
    I have tried using it with DTD validation but somehow it is not working. Can anyone pls suggest me the solution to parse a validated xml message into the database tables.

    I have to parse a validated xml message into oracle database tables.
    I have tried using it with DTD validation but somehow it is not working. Can anyone pls suggest me the solution to parse a validated xml message into the database tables.

  • How To Generate Objects From XML and DTD?

    Are there tools to generate objects from dtd's and xml files?
    If this is not possible for some reason: is there a tool to generate classes from a dtd?
    I can not find the "XML Java Class Generator" (from oracle) anymore.

    XMLBeans
    There are other solutions, but I know this one is pretty good.

  • Import XML or DTD

    I am a video editor on Avid products. So please excuse the
    total ignorance of my question concerning Flash.
    Avid can generate XML and DTD metadata files from video
    sequences. Often used to create chapter markers for DVD. But I can
    also set the metadata to link to a URL. My client wants a video
    (QT, WMV, FLV, whatever) that plays on the desktop, and when it
    hits certain points, a web browser window opens with pertinent info
    relating to the video. Sort of like a powerpoint presentation. Is
    Flash one way to do this? Is ActiveScript the key?
    Thanks for any advice you can give.
    Curtis

    We currently do not have a DTD to DB Schema utility becsuse DTDs to not describe the datatypes to be used. It is also the wrong way to design DB Schemas which is why we have the XML SQL Utility that goes the other way.
    Oracle XML Team

  • Where are FrameMaker 10 video tutorials on XML and DITA features?

    Salutations, everyone!  Besides YouTube, what video-based training/tutorial resources do you suggest for a 1-year FM10 and XML/DTD user?  I bought FM10 for my personal laptop about 1 year ago, and I have also been learning at the same time all about XML and DTDs within the Oxygen XML suite ( integrated development environment).  I love it!  But now that I'm a "seasoned beginner", I would like to transition to working with XML/DITA and become proficient with structured docs in FM10.  I want to increase my rate of learning, particularly during the next two months.
    Cheers!

    Hi Agape Guy,
    Please visit the following official link for starting with DITA:
    http://tv.adobe.com/watch/dita-12/framemaker-10-dita-features/
    Regards,
    Saurabh

  • Parsing XML with DTD residing in jar file

    Hi,
    I have problems using crimson parser for my program under JDK 1.4.0b2. It attempts to parse an xml file with SAX. The corresponding lies in a jar file in a different directory but reachable through the classpath. All I get is an exception.
    org.xml.sax.SAXParseException: Relative URI "my.dtd"; kann nicht ohne eine Dokument-URI aufgel�st werden.
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3121)
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3115)
    at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2702)
    at org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2674)
    at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1125)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
    at org.xml.sax.helpers.XMLReaderAdapter.parse(XMLReaderAdapter.java:223)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:326)
    I used Xerces before and it worked fine. I already searched the community for that problem. All hints I found assume that xml file and dtd are in the same directory. Setting the systemId of the input source doesn't fix the problem.
    Is there anyone out there knowing what to do?
    Thanks,
    Thorsten

    Use a Resolver to map a PUBLIC name to a local name:
    <!DOCTYPE DOC PUBLIC "-//gaskin.de//XMLDOC 1.0//EN"
    "http://www.gaskin.de/dtd/xmldoc.dtd">
    public static register() {
       ClassLoader loader = Resolver.class.getClassLoader();
       registerCatalogEntry(
          "-//gaskin.de//XMLDOC 1.0//EN",
          "de/gaskin/resources/dtd/XMLDOC.DTD",
          loader);
    }

  • Help appending dtd's to XML programmatically(SAX parser)

    Hi
    If i want to validate an xml by writing a dtd and if i want to append that dtd to my xml programattically then how will i do it
    i am using java's sax parser currently .
    can any one help me out.
    Reply will b appritiated
    Regards
    Geetanjali P.

    Parsers are for inputting XML data. Your question is about outputting XML data, so your choice of parser is irrelevant. What is relevant is how you are outputting your XML, and you didn't say anything about that. So please do.

  • Parsing XML and Storing values in instance variable

    hi,
    i'm new to XML.
    here i'm trying to parse an XML and store their element data to the instance variable.
    in my main method i'm tried to print the instance variable. but it shows "" (ie it print nothing ).
    i know the reason, its becas of the the endElement() event generated and it invokes the characters() and assigns "" to the instance variable.
    my main perspective is to store the element data in instance variable.
    thanks in advance.
    praks
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class mysax extends DefaultHandler
         String ctelement;
         CharArrayWriter contents;
         String vname1,vrcbreg1,vaddress1,vcountry1,vtelephone1,vfax1;
         String vname,vrcbreg,vaddress,vcountry,vtelephone,vfax;
         public mysax()
              vname1 = null;
              vrcbreg1 = null;
              vaddress1 = null;
              vcountry1 = null;
              vtelephone1 = null;
              vfax1 = null;
              contents= new CharArrayWriter();
         public void doparse(String url) throws Exception
              SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    ParserAdapter pa = new ParserAdapter(sp.getParser());
    pa.setContentHandler(this);
    pa.parse(url);          
         public void startElement(String namespace,String localName,String qName,Attributes atts)
              ctelement = localName;     
         public void endElement(String uri,String localName,String qName) throws SAXException
         public void characters(char[] ch,int start, int length) throws SAXException
              try
                   if(ctelement.equals("name"))
                        vname = new String (ch,start,length);
                        System.out.println("The method "+vname1);
              }catch (Exception e)
                   System.out.println("The exception "+e);
         public static void main(String args[])
              try
              mysax ms = new mysax();
              ms.doparse(args[0]);
              System.out.println("the contents name "+ms.vname1);
              catch(Exception e)
                   System.out.println("this is exception at main" +e);
    my XML looks like
    <coyprofile_result>
    <company>     
    <name>abcTech</name>
    <rcbreg>123456789</rcbreg>
    <address>Singapore</address>
    <country>sg</country>
    <telephone>123456</telephone>
    <fax>123155</fax>
    </company>
    </coyprofile_result>

    I believe that the problem has to do with the value you assign to ctelement. You are assigning the value of localName to ctElement, however for the element: <name>...</name> the localname is empty string i.e. "", but qName equals "name". Because you are assigning empty string to ctElement, when you do the comparison in characters of ctElement to "name" it will always be false. So in startElement change it to ctElement = qName; Try it and see if it works. I have produced similar programs and it works for me.
    Hope this helps.

  • Parsing XML and HTML

    Is there any way to parse a XML file and covert it to a result set using SQL and PLSQL?

    Yes. Oracle SQL and PL/SQL can use the Oracle supplied XML Parser to create XML and to extract attributes and rows from XML.
    Refer to [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14259/toc.htm]Oracle® XML DB Developer's Guide.

  • Eastern European characters in XML and parsing

    Hi all,
    I have a problem with XML parsing within Java code with special Eastern European characters.
    Whenever there is EE character within tags it reports:
    WARNING (12847): CORE3283: stderr: org.xml.sax.SAXParseException: The element type "CodeMeaning" must be terminated by the matching end-tag "</CodeMeaning>".
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:134)
    Obviously special character is in CodeMeaning XML tag. XML is well formed and syntactically OK and without special characters works OK. Does anyone have any suggestion how to force special characters in XML?

    Would you send a sample data for test? What is the encoding for your XML doc?

  • HOW TO KNOW VALID XML WITH DTD ? WITHOUT PARSING  ?

    i am creating the xml file
    i need to validate the xml with DTD to confirm is it valid or not ?
    with out parsing...
    could you tell me how ?
    Durga

    without parsing u cant do it..

  • XML Output and DTD

    I use Reports9i to generate a XML report output.
    How do I generate the associated DTD? Do I need to manually
    write it.
    Thanks,
    Alex

    To add, if your application needs a DTDyou an use any XML IDE ( like xmlspy) to automatically write a bare minimal DTD for the XML and you can modify to impose /alter the restrictions
    Thanks
    The Oracle Reports team

  • XML SAX dtd Validation Problem

    Hi,
              I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
              When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
              Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
              Code Snippet:
              boolean isValid = false;
              try {
              // Create and configure factory
              SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
              factory.setValidating(true);
              factory.setNamespaceAware(true);
              // To be notified of validation errors in the XML document,
              // add a custom error handler to the document builder
              PIMSFeedFileValidationHandler handler
              = new PIMSFeedFileValidationHandler();
              // Create and Configure Parser
              SAXParser parser = factory.newSAXParser();
              parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
              parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
              // Set reader with entityResolver for dtd
              XMLReader xmlReader = parser.getXMLReader();
              xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
              // convert file to URL, as it is a remote file
              URL url = super.getFile().toURL();
              // Open an input stream and parse
              InputStream is = url.openStream();
              xmlReader.setErrorHandler(handler);
              xmlReader.parse(new InputSource(is));
              is.close();
              // get the result of parsing the document by checking the
              // errorhandler's isValid property
              isValid = handler.isValid();
              if (!isValid) {
              LOGGER.warn(handler.getMessage());
              LOGGER.debug("XML file is valid XML? " + isValid);
              } catch (ParserConfigurationException e) {
              LOGGER.error("Error parsing file", e);
              } catch (SAXException e) {
              LOGGER.error("Error parsing file", e);
              } catch (IOException e) {
              throw new FeedException(e);
              return isValid;
              See stack trace below for a little more info.
              2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
              2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
              VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
              2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
              2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
              org.xml.sax.SAXParseException: Element type "Session" must be declared.
              org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
              org.xml.sax.SAXParseException: Element type "Volume" must be declared.
              org.xml.sax.SAXParseException: Element type "Written" must be declared.
              org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
              org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
              … continues for all the elements in the doc
              2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
              2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
              Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
              Thanks in Advance
              Adam

    It looks like you clicked on "Post" before you got around to explaining your problem. I don't see any error messages or any description of what was supposed to happen and what happened instead.
    Now, I don't know anything about XML Schema, but just guessing at how that unique name feature might be designed, and just guessing that your unique name is actually in the <userId> element, I would suggest that this:
    <xsd:unique name="un_name"> 
      <xsd:selector xpath="USER"/> 
      <xsd:field xpath="."/> 
    </xsd:unique> is at fault because it doesn't mention the <userId> element anywhere.

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • JSF, tiles, xml and xsl

    Good days people, I am employed at an app that wants to integrate JSF, tiles, xml and xsl.
    Basically the app receives information of the user's interfaz, builds an url with the above mentioned information and invokes to a service web that a xml returns with the information. The idea is to generate the exit in format html or wml with an insole(staff) xsl and to send the result in this format to every jsp that is going to form a part of the page that it will generate tiles. at first I understand that it is feasible, i�d like to know if someone already has done it and since it has done it.
    Just now what I have is a managed bean that receives the parameters of the altar frontal and invokes a method of a service, like this:
    public String encuentra(){
    //deja los atributos privados rellenos.
    String mensaje ;
    crearYRellenarBusquedaVO();
    try {
    setResultado(this.getServicio().obtenerResultadosWML(this.getBusquedaVO()));
    mensaje="succesNoJS";
    }catch(java.lang.IllegalArgumentException e){
    mensaje="error";
    }catch(es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException e1){
    mensaje="error";
    }catch(Exception e2){
    mensaje="error";
    return mensaje;
    public String obtenerResultadosWML(es.yell.frontlite.service.impl.BusquedaVO busquedaVO){
    if (busquedaVO == null){
    throw new IllegalArgumentException(
    "obtenerResultadosJSdesactivado(es.yell.frontlite.service.impl.BusquedaVO busquedaVO) - 'busquedaVO' no puede ser nulo.");
    try{
    return this.manejarObtenerResultadosWML(busquedaVO);
    }catch(es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException e1){
    throw new es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException(
    "Error ejecutando el servicio String obtenerResultadosJSdesactivado(es.yell.frontlite.service.impl.BusquedaVO busquedaVO). " + e1.getCause(),e1);
    }catch(Exception e){
    throw new es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException(
    "Error ejecutando el servicio String obtenerResultadosJSdesactivado(es.yell.frontlite.service.impl.BusquedaVO busquedaVO). " + e.getCause(),e);
    //it returns html code!
    protected String manejarObtenerResultadosWML(es.yell.frontlite.service.impl.BusquedaVO busquedaVO)
    throws java.lang.Exception{
    try{
    // xmlOrigen has full xml response from server
    String xmlOrigen = manejarObtenerResultadosJSActivado(busquedaVO);
    Source xmlSource = new StreamSource(new StringBufferInputStream(xmlOrigen));
    Source xsltSource = new StreamSource(SrvBusquedaNoxtrumServiceImpl.class.getResourceAsStream(Constantes.XSL_FILE));
    StringWriter cadenaSalida = new StringWriter();
    Result bufferResultado = new StreamResult(cadenaSalida);
    TransformerFactory factoriaTrans = TransformerFactory.newInstance();
    Transformer transformador = factoriaTrans.newTransformer(xsltSource);
    transformador.transform(xmlSource, bufferResultado);
    System.out.println(cadenaSalida.toString());
    return cadenaSalida.toString();
    }catch(Exception e2){
    throw new es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException (e2.getMessage());
    With this exit in html, since(as,like) how could i forward it towards a jsp especially?
    faces-config.xml
    <navigation-rule>
    <from-view-id>/index.jsp</from-view-id>
    <navigation-case>
    <from-outcome>succesNoJS</from-outcome>
    <to-view-id>/jsDesactivado.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>error</from-outcome>
    <to-view-id>/error.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    index.jsp
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <f:view>
    <f:loadBundle basename="MessageResources" var="msg"/>
    <head>
    <title>
    ${msg.titulo}
    </title>
    </head>
    <body>
    <h:form id="formulario">
    Que:
    <h:inputText id="campoQue" value="#{yellProxy.campoQue}" />
    Donde
    <h:inputText id="campoDonde" value="#{ yellProxy.campoDonde}" />
    <h:commandButton id="boton" value="Encuentra" action="#{yellProxy.encuentra}"/>
    </h:form>
    </f:view>
    </body>
    </html>
    jsDesactivado.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri=" http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    " http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h1>JSP Page</h1>
    jsDesactivado!!
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    <jsp:getProperty name="yellProxy" property="resultado"/>
    </body>
    </html>
    If you could pass me a simple example of use of an app that uses JSF, tiles, xml and xsl, i�be grateful
    regards a lot!

    We too (at Viking Freight) would also be very interested to see if anybody
    has produced such a useful series of classes...
    Frank Lees, Developer
    -----Original Message-----
    From: Amin, Kamran [mailto:kamran.aminframeworkinc.com]
    Sent: Wednesday, January 19, 2000 12:11 PM
    To: 'Forte User'
    Subject: (forte-users) XML and XSL in Forte
    Has anybody integrated an XSL parser with Forte. I know Forte provides us
    with an XML parser but that does not help with parsing XSL. There a lot of
    parsers written in JAVA but that will not integrate well with Forte. We
    need something that will be easy to integrate with Forte. This parser will
    take our XML and XSL to give us a result set. If anybody can comment on the
    subject or share some information I would appreciate it.
    thanks in advance.
    ka
    For the archives, go to: http://lists.sageit.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.sageit.com

Maybe you are looking for