Parse xml file with validating againat dtd

i have a xlm file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map SYSTEM "map.dtd">
<map width="20" height="15" goal="25" name="eXtreme Labyrinth of Dooom">
<random-item type='lantern' amount='5' />
<random-item type='health' amount='10' />
<tile x="14" y="0" type="wall">
<renderhint>wall:rock,cracked</renderhint>
</tile>
<tile x="15" y="0" type="wall" />
<tile x="16" y="0" type="floor">
<renderhint>floor:marble,cracked</renderhint>
</tile>
<tile x="17" y="0" type="floor">
<renderhint>floor:stone,rubble</renderhint>
</tile>
<tile x="18" y="0" type="floor" />
<tile x="0" y="1" type="floor" />
<tile x="1" y="1" type="floor" startlocation="1" />
<tile x="2" y="1" type="floor" />
<tile x="3" y="1" type="floor">
<item type="treasure">Bar of Silver</item>
<renderhint>floor:stone,blood</renderhint>
</tile>
<tile x="4" y="1" type="wall" />
<tile x="5" y="1" type="wall" />
<tile x="6" y="1" type="wall">
<renderhint>wall:bricks,cracked</renderhint>
</tile>
</map>and a dtd document like:
<!ELEMENT map (random-item+, tile+)>
<!ATTLIST map
width CDATA #REQUIRED
height CDATA #REQUIRED
goal CDATA #REQUIRED
name CDATA #REQUIRED
<!ELEMENT random-item EMPTY>
<!ATTLIST random-item
type (armour|health|sword|treasure|lantern) #REQUIRED
amount CDATA #REQUIRED
<!ELEMENT tile (item|renderhint)*>
<!ATTLIST tile
x CDATA #REQUIRED
y CDATA #REQUIRED
type (exit|floor|wall) #REQUIRED
startlocation CDATA #IMPLIED
<!ELEMENT item (#PCDATA)>
<!ATTLIST item
type (armour|health|sword|treasure|lantern) #REQUIRED
<!ELEMENT renderhint (#PCDATA)>i need to validate the xml file against the dtd document and parse it to java using DOM.
Can anyone give ma any suggestions on how to do it?
thank you

i have started my coding like:
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.*;
class loadxml
    public static void main(String[] args)
     try {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setValidating(true);
          factory.setIgnoringElementContentWhitespace(true);
          DocumentBuilder parser = factory.newDocumentBuilder();
          Document doc = parser.parse(new File("hallways.xml"));
          loadxml load = new loadxml();
          load.parseNode(doc);
     } catch (ParserConfigurationException e) {
          e.printStackTrace();
     } catch (SAXException e) {
          e.printStackTrace();
     } catch (IOException e) {
          e.printStackTrace();
    public void parseNode (Node node) throws IOException
           // here is where i have problem with
}since in my xml file, i have got ATTLIST, this ready confuses me when i try to coding it.
Can anyone help me, please.
Thank you.
Edited by: mujingyue on Mar 12, 2008 3:10 PM

Similar Messages

  • How to parse XML file with namesapce?

    Hi,
       I am trying to parse an xml file having namespace. But no data is returned.
    Sample Code:
    public class XMLFileLoader
    var xml:XML = new XML();
    var myXML:XML = new XML();
    var XML_URL:String = "file:///C:/Documents and Settings/Administrator/Desktop/MyData.xml";
    var myLoader:URLLoader = null;
    public function XMLFileLoader()
    var myXMLURL:URLRequest = new URLRequest(XML_URL);
    myLoader= new URLLoader(myXMLURL);
    myLoader.addEventListener(Event.COMPLETE,download);
    public function download(event:Event):void
    myXML = XML(myLoader.data);
    var ns:Namespace=myXML.namespace("xsi");
    for(var prop:String in myXML)
         trace(prop);
    //Alert.show(myXML..Parameters);
    //trace("Data loadedww."+myXML.toString());
    //Alert.show(myXML.DocumentInfo.attributes()+"test","Message");
    The XML Contains the following format.
    <Network xmlns="http://www.test.com/2005/test/omc/conf"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.test.com/2005/test/omc/conf/TestConfigurationEdition3proposal4.xsd">
        <TestDomain>
          <WAC>
            <!--Release Parameter  -->
            <Parameters ParameterName="ne_release" OutageType="None"
                        accessRight="CreateOnly" isMandatory="true"
                        Planned="false"
                        Reference="true" Working="true">
              <DataType>
                <StringType/>
              </DataType>
              <GUIInfo graphicalName="Release"
                       tabName="All"
                       description="Describes the release version of the managed object"/>
            </Parameters>
    </TestDomain>
    </Network>
    Any sample code how to parse this kind of xml file with namespaces...
    Regards,
    Purushotham

    i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
    i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
    screenshot

  • Parsing XML file with different languages (Xerces)

    How do we code or program to an XML file with different
    languages , say english and spanish. WHen we parse such a document with the default locale , the presence of special characters throws errors .For eg when I use xerces and use
    DOMParser parser = new DOMParser();
    try
    // Parse the XML Document
    parser.parse(xmlFile);
    catch (SAXException se)
    se.printStackTrace();
    org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xfc) was found in the element content of the document.
    System Error:          void org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
    So what locale do we set before we parse ?How to handle this problem

    You need an encoding attribute in the xml declaration. If you don't, the parser assumes UTF-8, which are ASCII characters up to 127 - useful (only) for English.
    So, something like this would allow you to use characters above 127, ISO-8859-1 is the encoding used by standard PCs.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    You can find a (offical) list of encodings at:
    http://www.iana.org/assignments/character-sets
    I'm not sure about mixing various encodings. I think you have to resort external parsed entities, which can have their own encoding, but I think you cannot mix encodings in one XML file.
    Good luck.

  • Produce XML file with a given DTD

    I have only installed XSU, and I was hopping to use pl/sql package XMLGEN to generate XML with a given DTD and a sql query.
    I can't find input parameter for DTD. Well it seems logical as both DTD and SQL are for defining the XML output file.
    How can this be done ?
    Thanks.
    /Kwan

    Sure. You could write an EntityResolver to do that. Attach it to your DocumentBuilder or XMLReader, depending on which you are using.

  • Parsing XML file with the word "Infinity" in it

    I am having a problem within Flex that parses an XML file,
    one of the text names within the file contains the word "Infinity".
    Unfortunately this is a constant within Flex and the element of my
    array does not think it is a text string but a value. I have tried
    type setting the xml element, and putting escape characters around
    the text but nothing works. If I change the text to lowercase
    "infinity" it works fine.
    Any help greatly appreciated.

    This sounds like a bug. Can you file it, with a small code
    example that illustrates it, here:
    http://bugs.adobe.com/jira
    Thanks!
    matt horn
    flex docs

  • Parse XML file with regex

    Hi,
    Is that possible to parse a xml file using regular expressions....if s what is the API needed
    thanx in advance

    Is that possible to parse a xml file using regular
    expressions....if s what is the API neededI'm sure it can be done. Here's the regex API:
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/package-summary.html
    http://www.javaregex.com/tutorial.html
    But that's not where regex is for. Better have a look at this:
    http://java.sun.com/xml/

  • Validating generated XML file with DTD

    Hello all,
    my requirement is to test the XML file with its DTD.
    we are creating an XML file, before writing it on the application server , we need to test it with its DTD.
    i found one method set_validating in the interface if_ixml_parser , for validating XML file, but not getting an idea how to use it, like how to link the DTD to XML etc.
    if i try to use the above method am getting the following error:
    Unable to retrieve the external entity 'd:\dtdfile.dtd'.
    where 'd:\dtdfile.dtd' is the path of the DTD file included in the Doctype of the XML file.
    Please help me to solve this.
    Thx in advance.

    Hello,
    Did you find your answer ?
    I know how to validate an XML file an internal DTD, but not an external one... If you know, can you pelase advice ?
    If you didn't found yet, you need to use method get_reason() to get the description of the error.
    best regards,
    Gilles.

  • To read XML file with DTD in SSIS

    Hi,
    My SISS package needs to read .mak file and store it in a sql tables.
    I am receiving xml file content in mak file extension with DTD. So I couldn't read through XML source shows error DTD is prohibited in this document. After removing DTD by manually, the xml file has multiple outputs.
    Please guide me how to remove DTD by coding and also I don't have xsd and xsl file for this only mak file.
    Thanks.

    Thanks Visakh for your answer.
    I have tried in XML task which described in the thread. But I couldn't remove DTD file, I am getting following error,
    [XML Task] Error: An error occurred with the following error message: "Could not find a part of the path 'C:\Program Files (x86)\FAST\Builder\bin\makefile.dtd'.".
    As I said before I am receiving in .mak file extension. The beginning of file content is like below,
    <?xml version='1.0'?>
    <!DOCTYPE makefile SYSTEM "file:///C:/ProgramFiles
    (x86)/FAST/Builder/bin/makefile.dtd"[
    <!ENTITY % default-content-type "'text/html'">
    <!ENTITY prjdir "G:\cdrom\Employees_2014_02">
    <!ENTITY imgdir "G:\images\forms\gifs">
    <!ENTITY foddir "G:\SOFT\FORMS CD\Feb14">
    <!ENTITY ccdir "Y:\Content">
    ]>
    <makefile>
    &fsysdse;
    <content-collection id="b1" title="Employers and Employees" filename="&ccdir;\Employees_2014_02.nfo" password=""> ....
    After replace all variable (prjdir,imgdir,fodder,ccdir) into values specified in the entity tag, I removed above underlined part - so the xml file is ready without DTD part and able to use in
    XML source. I have received 6 outputs from XML source.
    My question is how to do this manual work in SSIS? It’s not only one file, so many files needs to updated SQL tables automatically so everything should be done by coding.
    Please guide me in which way I can achieve this?
    If you want to do this in SSIS
    one way is to use Script Task to parse the file and remove the DTD part.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Parse exisitng xml file and recreate another xml file with different struct

    Is it possible in java using dom parser to parse an exisiting xml file and recreate a new xml file from data obtained by parsing old xml file.
    I checked on old forum threads and everywhere either parsing xml file has been explained or creating new xml file from scratch has been shown.
    Any examples/guidance will be appreciated....

    The general process is:
    Document dom1 = ... // the parsed document
    Document dom2 = ... // new document constructed on the fly
    Node nD1 = ... // some random node found in dom1
    // copy the node from dom1 and associate with dom2
    Node nD2 = dom2.importNode(nD1, true);
    // ... treat nD2 as a node which can now be inserted into dom2 ...
    Node otherD2 =  ... // some other node already in dom2
    otherD2.appendChild(nD2);Note, in this example the nD1 node is copied (including any sub-nodes) into a new node, nD2. You can alternately move the node from one Document to another using Document.adoptNode(), however this may fail (see the javadoc).

  • File Adapter : read XML file with data validation and file rejection ?

    Hello,
    In order to read a XML file with the file adapter, I have defined a XSD that I have imported to my project.
    Now the File Adapter reads the file correctly but it does not give an error when:
    - the data types are not valid. Ex: dateTime is expected in a node and a string is provided
    - the XML file has invalid attributes.
    How can I manage error handling for XML files ?
    Should I write my own Java XPath function to validate the file after is processed ? (here is an example for doing this : http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21058568.html)
    Thanks.

    one option is to specify validateXML on the partnerlink (that describes the file adapter endpoint) such as shown here
    <partnerLinkBinding name="StarLoanService">
    <property name="wsdlLocation"> http://<hostname>:9700/orabpel/default/StarLoan/StarLoan?wsdl</property>
    <property name="validateXML">true</property>
    </partnerLinkBinding>
    hth clemens

  • Reading xml file with sax parser: unknown protocol: c

    Hi,
    I've been googling around, and the best I can find is that the file name:
    File test = new File("lib/test/parseTest/validate-test.xml");should be a url:
    File test = new File("File://lib/test/parseTest/validate-test.xml");but I'm working on a linux machine and can't put "File://c:/pathToFile/file.xml"
    Also, I did some testing and I can read a small xml file with just a few elements, but on large complex files, I get that error.
    anyone ever run into this before?
    bp
    Edited by: badperson on Nov 1, 2008 2:19 PM

    badperson wrote:
    I've been googling around, and the best I can find is that the file name:
    File test = new File("lib/test/parseTest/validate-test.xml");should be a url:
    File test = new File("File://lib/test/parseTest/validate-test.xml");
    No, that's wrong. The parameter for that constructor is a file path (relative or absolute). Not a URL. You must have misunderstood whatever you read.
    but I'm working on a linux machine and can't put "File://c:/pathToFile/file.xml"What kind of a Linux machine is this which has a C drive? You must have misunderstood whoever told you to do that.

  • Can I validate an XML file using an external DTD

    Hi,
    I'm trying to use an external DTD to validate an XML
    file (which does not refer to this DTD). The java docs that ship
    with the XML parser aren't clear on how exactly to do this (or
    whether it can be done). I'd appreciate any advice on how I
    should perform this operation.
    Here's what I'm doing right now.
    1) The Java file
    import oracle.xml.parser.v2.*;
    public class ParseWithExternalDTD
    public static void main(String args[]) throws Exception
    DOMParser dp=new DOMParser();
    dp.parseDTD
    ("file:d:/jdk1.2/sample/test/family.DTD","family");
    DTD dtd=dp.getDoctype();
    dp.setDoctype(dtd);
    dp.parse("file:d:/jdk1.2/sample/test/family.xml");
    System.out.println("Finished with no errors!");
    2) The family.DTD file
    <!ELEMENT family (member*)>
    <!ATTLIST family lastname CDATA #REQUIRED>
    <!ELEMENT member (#PCDATA)>
    <!ATTLIST member memberid ID #REQUIRED>
    <!ATTLIST member dad IDREF #IMPLIED>
    <!ATTLIST member mom IDREF #IMPLIED>
    3) The family.xml file
    <?xml version="1.0" standalone="no"?>
    <family lastname="Smith">
    <TagToFoilParserValidation>
    </TagToFoilParserValidation>
    <member memberid="m1">Sarah</member>
    <member memberid="m2">Bob</member>
    <member memberid="m3" mom="m1" dad="m2">Joanne</member>
    <member memberid="m4" mom="m1" dad="m2">Jim</member>
    </family>
    4) The output
    Finished with no errors!
    As you can see, the DOMParser failed to validate the family.xml
    file against the family dtd otherwise, it would have reported a
    validation error when it came across the
    TagToFoilParserValidation.
    Any insight as to what I'm doing wrong would be much appreciated.
    Sincerely,
    Keki
    Project Iona
    Manufacturing Applications
    Oracle Corporation
    The views and opinions expressed here are
    my own and do not reflect the views and
    opinions of Oracle Corporation
    null

    Keki Burjorjee (Oracle) (guest) wrote:
    : 2 further questions related to this issue.
    : 1) Say I am using XSLT to transform A.xml into B.xml, and I
    : want to embed a reference to B.dtd within the B.xml file. Is
    : there an XSLT command which will allow me to do this?
    : 2) Is it possible for your team to give me a mechanism whereby
    I
    : can preset the xml parser to validate the next xml file (or
    : inputstream) it receives against a particular DTD? This scheme
    : does not require the dtd to be present within the XML file
    : Thanks,
    : - Keki
    : Oracle XML Team wrote:
    : : What you are doing wrong is not including a reference to the
    : : applicable DTD in your XML document. Without it there is no
    : way
    : : that the parser knows what to validate against. Including
    the
    : : reference is the XML standard way of specifying an external
    : : DTD. Otherwise you need to embed the DTD in your XML
    Document.
    : : Oracle XML Team
    : : http://technet.oracle.com
    : : Oracle Technology Network
    : : Keki Burjorjee (guest) wrote:
    : : : Hi,
    : : : I'm trying to use an external DTD to validate an XML
    : : : file (which does not refer to this DTD). The java docs that
    : : ship
    : : : with the XML parser aren't clear on how exactly to do this
    : (or
    : : : whether it can be done). I'd appreciate any advice on how I
    : : : should perform this operation.
    : : : Here's what I'm doing right now.
    : : : 1) The Java file
    : : : import oracle.xml.parser.v2.*;
    : : : public class ParseWithExternalDTD
    : : : public static void main(String args[]) throws Exception
    : : : DOMParser dp=new DOMParser();
    : : : dp.parseDTD
    : : : ("file:d:/jdk1.2/sample/test/family.DTD","family");
    : : : DTD dtd=dp.getDoctype();
    : : : dp.setDoctype(dtd);
    : : : dp.parse("file:d:/jdk1.2/sample/test/family.xml");
    : : : System.out.println("Finished with no errors!");
    : : : 2) The family.DTD file
    : : : <!ELEMENT family (member*)>
    : : : <!ATTLIST family lastname CDATA #REQUIRED>
    : : : <!ELEMENT member (#PCDATA)>
    : : : <!ATTLIST member memberid ID #REQUIRED>
    : : : <!ATTLIST member dad IDREF #IMPLIED>
    : : : <!ATTLIST member mom IDREF #IMPLIED>
    : : : 3) The family.xml file
    : : : <?xml version="1.0" standalone="no"?>
    : : : <family lastname="Smith">
    : : : <TagToFoilParserValidation>
    : : : </TagToFoilParserValidation>
    : : : <member memberid="m1">Sarah</member>
    : : : <member memberid="m2">Bob</member>
    : : : <member memberid="m3" mom="m1" dad="m2">Joanne</member>
    : : : <member memberid="m4" mom="m1" dad="m2">Jim</member>
    : : : </family>
    : : : 4) The output
    : : : Finished with no errors!
    : : : As you can see, the DOMParser failed to validate the
    : : family.xml
    : : : file against the family dtd otherwise, it would have
    : reported
    : : a
    : : : validation error when it came across the
    : : : TagToFoilParserValidation.
    : : : Any insight as to what I'm doing wrong would be much
    : : appreciated.
    : : : Sincerely,
    : : : Keki
    : : : Project Iona
    : : : Manufacturing Applications
    : : : Oracle Corporation
    : : : The views and opinions expressed here are
    : : : my own and do not reflect the views and
    : : : opinions of Oracle Corporation
    1) No XSLT commands exist that allow you to embed a DTD while
    doing the transformation.
    2) You can use the setDocType() method in the parser, to set a
    DTD based on which the XML document will be validated. The
    parseDTD() method allows you to parse a DTD file separately and
    get a DTD object. Here is a sample code :
    DOMParser domparser = new DOMParser();
    domparser.setValidationMode(true);
    // parse the DTD file
    domparser.parseDTD(new FileReader(dtdfile));
    DTD dtd = domparser.getDocType();
    // Parse XML file - XML file will be validated based on the DTD.
    domparser.setDocType(dtd);
    domparser.parse(new FileReader(xmlfile));
    Document doc = domparser.getDocument();
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • Create xml file with values from context

    Hi experts!
    I am trying to implement a WD application that will have some input fields, the value of those input fields will be used to create an xml file with a certain format and then sent to a certain application.
    Apart from this i want to read an xml file back from the application and then fill some other context nodes with values from the xml file.
    Is there any standard used code to do this??
    If not how can i do this???
    Thanx in advance!!!
    P.S. Points will be rewarded to all usefull answers.
    Edited by: Armin Reichert on Jun 30, 2008 6:12 PM
    Please stop this P.S. nonsense!

    Hi,
    you need to create three util class for that:-
    XMLHandler
    XMLParser
    XMLBuilder
    for example in my XML two tag item will be there e.g. Title and Organizer,and from ur WebDynpro view you need to pass value for the XML tag.
    And u need to call buildXML()function of builder class to generate XML, in that i have passed bean object to get the values of tags. you need to set the value in bean from the view ui context.
    Code for XMLBuilder:-
    Created on Apr 4, 2006
    Author-Anish
    This class is to created for having function for to build XML
    and to get EncodedXML
      and to get formated date
    package com.idb.events.util;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import com.idb.events.Event;
    public class XMLBuilder {
    This attribute represents the XML version
         private static final double VERSION_NUMBER = 1.0;
    This attribute represents the encoding
         private static final String ENCODING_TYPE = "UTF-16";
         /*Begin of Function to buildXML
    return: String
    input: Event
         public String buildXML(Event event) {
              StringBuffer xmlBuilder = new StringBuffer("<?xml version=\"");
              xmlBuilder.append(VERSION_NUMBER);
              xmlBuilder.append("\" encoding=\"");
              xmlBuilder.append(ENCODING_TYPE);
              xmlBuilder.append("\" ?>");
              xmlBuilder.append("<event>");
              xmlBuilder.append(getEncodedXML(event.getTitle(), "title"));
              xmlBuilder.append(getEncodedXML(event.getOrganizer(), "organizer"));
              xmlBuilder.append("</event>");
              return xmlBuilder.toString();
         /End of Function to buildXML/
         /*Begin of Function to get EncodedXML
    return: String
    input: String,String
         public String getEncodedXML(String xmlString, String tag) {
              StringBuffer begin = new StringBuffer("");
              if ((tag != null) || (!tag.equalsIgnoreCase("null"))) {
                   begin.append("<").append(tag).append(">");
                   begin.append("<![CDATA[");
                   begin.append(xmlString).append("]]>").append("</").append(
                        tag).append(
                        ">");
              return begin.toString();
         /End of Function to get EncodedXML/
         /*Begin of Function to get formated date
    return: String
    input: Date
         private final String formatDate(Date inputDateStr) {
              String date;
              try {
                   SimpleDateFormat simpleDateFormat =
                        new SimpleDateFormat("yyyy-MM-dd");
                   date = simpleDateFormat.format(inputDateStr);
              } catch (Exception e) {
                   return "";
              return date;
         /End of Function to get formated date/
    Code for XMLParser:-
    Created on Apr 12, 2006
    Author-Anish
    This is a parser class
    package com.idb.events.util;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import com.idb.events.Event;
    import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;
    public class XMLParser {
    Enables namespace functionality in parser
         private final boolean isNameSpaceAware = true;
    Enables validation in parser
         private final boolean isValidating = true;
    The SAX parser used to parse the xml
         private SAXParser parser;
    The XML reader used by the SAX parser
         private XMLReader reader;
    This method creates the parser to parse the user details xml.
         private void createParser()
              throws SAXException, ParserConfigurationException {
              // Create a JAXP SAXParserFactory and configure it
              SAXParserFactory saxFactory = SAXParserFactory.newInstance();
              saxFactory.setNamespaceAware(isNameSpaceAware);
              saxFactory.setValidating(isValidating);
              // Create a JAXP SAXParser
              parser = saxFactory.newSAXParser();
              // Get the encapsulated SAX XMLReader
              reader = parser.getXMLReader();
              // Set the ErrorHandler
    This method is used to collect the user details.
         public Event getEvent(
              String newsXML,
              XMLHandler xmlHandler,
              IWDMessageManager mgr)
              throws SAXException, ParserConfigurationException, IOException {
              //create the parser, if not already done
              if (parser == null) {
                   this.createParser();
              //set the parser handler to extract the
              reader.setErrorHandler(xmlHandler);
              reader.setContentHandler(xmlHandler);
              InputSource source =
                   new InputSource(new ByteArrayInputStream(newsXML.getBytes()));
              reader.parse(source);
              //return the results of the parse           
              return xmlHandler.getEvent(mgr);
    Code for XMLHandler:-
    Created on Apr 12, 2006
    Author-Anish
    This is a parser class
    package com.idb.events.util;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import com.idb.events.Event;
    Created on Apr 12, 2006
    Author-Anish
    *This handler class is created to have constant value for variables and function for get events,
        character values for bean variable,
        parsing thr date ......etc
    package com.idb.events.util;
    import java.sql.Timestamp;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.helpers.DefaultHandler;
    import java.util.*;
    import com.idb.events.Event;
    import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;
    public class XMLHandler extends DefaultHandler {
         private static final String TITLE = "title";
         private static final String ORGANIZER = "organizer";
         IWDMessageManager manager;
         private Event events;
         private String tagName;
         public void setManager(IWDMessageManager mgr) {
              manager = mgr;
    This function is created to get events
         public Event getEvent(IWDMessageManager mgr) {
              manager = mgr;
              return this.events;
    This function is created to get character for setting values through event's bean setter method
         public void characters(char[] charArray, int startVal, int length)
              throws SAXException {
              String tagValue = new String(charArray, startVal, length);
              if (TITLE.equals(this.tagName)) {
                   this.events.setTitle(tagValue);
              if (ORGANIZER.equals(this.tagName)) {
                   String orgName = tagValue;
                   try {
                        orgName = getOrgName(orgName);
                   } catch (Exception ex) {
                   this.events.setOrganizer(orgName);
    This function is created to parse boolean.
         private final boolean parseBoolean(String inputBooleanStr) {
              boolean b;
              if (inputBooleanStr.equals("true")) {
                   b = true;
              } else {
                   b = false;
              return b;
    This function is used to call the super constructor.
         public void endElement(String uri, String localName, String qName)
              throws SAXException {
              super.endElement(uri, localName, qName);
         /* (non-Javadoc)
    @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
    This function is used to call the super constructor.
         public void fatalError(SAXParseException e) throws SAXException {
              super.fatalError(e);
    This function is created to set the elements base on the tag name.
         public void startElement(
              String uri,
              String localName,
              String qName,
              Attributes attributes)
              throws SAXException {
              this.tagName = localName;
              if (ROOT.equals(tagName)) {
                   this.events = new Event();
         public static void main(String a[]) {
              String cntry = "Nigeria";
              XMLHandler xml = new XMLHandler();
              ArrayList engList = new ArrayList();
              engList = xml.getCountries();
              ArrayList arList = xml.getArabicCountries();
              int engIndex = engList.indexOf(cntry);
              System.out.println("engIndex  :: " + engIndex);
              String arCntryName = (String) arList.get(engIndex);
              System.out.println(
                   ">>>>>>>>>>>>>>>>>>>>" + xml.getArabicCountryName(cntry));
    Hope that may help you.
    If need any help , you are most welcome.
    Regards,
    Deepak

  • XML File Tags Validation Using Oracle.

    Dear Forum Members,
    I have a doubt regarding XML File Tags Validation.
    First I will explain My Requirement.
    1. I have to generate an XML File in a Predefined Format.
    2. User will add some data in the elements, or he may copy the same elements and change to some data like
    <Emp><Empno>10</Empno></Emp>
    The above tag will be generated by the application.
    User will copy the same and change to
    <Emp><Empno>20</Empno></Emp>.
    Now he want to Upload the Changed XML File to the Database table. This is done by parsing the XML File.
    The Creation and Parsing section is over. But before Parsing I want to check for the Validation of the XML Tag. i.e. whether the tag he has copied <Emp><Empno>10</Empno></Emp> is chaned by mistake to
    <Emp><Empno>10</Empno></Emps> or some other Mistakes.
    What I have to Do..
    Regards
    Madhu K

    I still think that my previous response is valid:
    If you e.g. include (concat) your DTD in your XML it will be validated against it!
    See e.g.:
    michaels>  select xmltype (xml_dtd || your_xml) your_validated_xml
      from (select '<SSDDATA>
                     <KEY><![CDATA[6707]]></KEY>
                     <FINISHED><![CDATA[This is a Finished data ]]></FINISHED>
                     <DEFAULT></DEFAULT>
                     <MIN></MIN>
                     <MAX></MAX>
                     <UNIT></UNIT>
                     <FORMULA></FORMULA>
                     <FORMULA></FORMULA>
                     <FORMULA-DESC></FORMULA-DESC>
                     <ADVANCED-FORMULA></ADVANCED-FORMULA>
                     <INTERNAL-ADAPT-DESC></INTERNAL-ADAPT-DESC>
                     <DATA-DESC-REPORT></DATA-DESC-REPORT>
                     <REV-DESC></REV-DESC>
                    </SSDDATA>' your_xml,
                   '<?xml version="1.0"?>
                    <!DOCTYPE SSDDATA [
                      <!ELEMENT SSDDATA (KEY,FINISHED,DEFAULT,MIN,MAX,UNIT,(FORMULA)+,FORMULA-DESC,ADVANCED-FORMULA,INTERNAL-ADAPT-DESC,DATA-DESC-REPORT,REV-DESC)>
                      <!ATTLIST SSDDATA xmlns CDATA #FIXED "">
                      <!ELEMENT KEY (#PCDATA)>
                      <!ATTLIST KEY xmlns CDATA #FIXED "">
                      <!ELEMENT FINISHED (#PCDATA)>
                      <!ATTLIST FINISHED xmlns CDATA #FIXED "">
                      <!ELEMENT DEFAULT EMPTY>
                      <!ATTLIST DEFAULT xmlns CDATA #FIXED "">
                      <!ELEMENT MIN EMPTY>
                      <!ATTLIST MIN xmlns CDATA #FIXED "">
                      <!ELEMENT MAX EMPTY>
                      <!ATTLIST MAX xmlns CDATA #FIXED "">
                      <!ELEMENT UNIT EMPTY>
                      <!ATTLIST UNIT xmlns CDATA #FIXED "">
                      <!ELEMENT FORMULA EMPTY>
                      <!ATTLIST FORMULA xmlns CDATA #FIXED "">
                      <!ELEMENT FORMULA-DESC EMPTY>
                      <!ATTLIST FORMULA-DESC xmlns CDATA #FIXED "">
                      <!ELEMENT ADVANCED-FORMULA EMPTY>
                      <!ATTLIST ADVANCED-FORMULA xmlns CDATA #FIXED "">
                      <!ELEMENT INTERNAL-ADAPT-DESC EMPTY>
                      <!ATTLIST INTERNAL-ADAPT-DESC xmlns CDATA #FIXED "">
                      <!ELEMENT DATA-DESC-REPORT EMPTY>
                      <!ATTLIST DATA-DESC-REPORT xmlns CDATA #FIXED "">
                      <!ELEMENT REV-DESC EMPTY>
                      <!ATTLIST REV-DESC xmlns CDATA #FIXED "">
                    ]>' xml_dtd
              from dual)
    YOUR_VALIDATED_XML                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    <?xml version="1.0"?>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                    <!DOCTYPE SSDDATA [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ELEMENT SSDDATA (KEY,FINISHED,DEFAULT,MIN,MAX,UNIT,(FORMULA)+,FORMULA-DESC,ADVANCED-FORMULA,INTERNAL-ADAPT-DESC,DATA-DESC-REPORT,REV-DESC)>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ATTLIST SSDDATA xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ELEMENT KEY (#PCDATA)>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ATTLIST KEY xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT FINISHED (#PCDATA)>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ATTLIST FINISHED xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                      <!ELEMENT DEFAULT EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ATTLIST DEFAULT xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ELEMENT MIN EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ATTLIST MIN xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT MAX EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ATTLIST MAX xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT UNIT EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                      <!ATTLIST UNIT xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                      <!ELEMENT FORMULA EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ATTLIST FORMULA xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ELEMENT FORMULA-DESC EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ATTLIST FORMULA-DESC xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ELEMENT ADVANCED-FORMULA EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ATTLIST ADVANCED-FORMULA xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ELEMENT INTERNAL-ADAPT-DESC EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ATTLIST INTERNAL-ADAPT-DESC xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT DATA-DESC-REPORT EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ATTLIST DATA-DESC-REPORT xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ELEMENT REV-DESC EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                      <!ATTLIST REV-DESC xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                    ]><SSDDATA>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                     <KEY><![CDATA[6707]]></KEY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                     <FINISHED><![CDATA[This is a Finished data ]]></FINISHED>                                                                                                                                                                                                                                                                            

  • Problems with reading XML files with ISO-8859-1 encoding

    Hi!
    I try to read a RSS file. The script below works with XML files with UTF-8 encoding but not ISO-8859-1. How to fix so it work with booth?
    Here's the code:
    import java.io.File;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.net.*;
    * @author gustav
    public class RSSDocument {
        /** Creates a new instance of RSSDocument */
        public RSSDocument(String inurl) {
            String url = new String(inurl);
            try{
                DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document doc = builder.parse(url);
                NodeList nodes = doc.getElementsByTagName("item");
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element element = (Element) nodes.item(i);
                    NodeList title = element.getElementsByTagName("title");
                    Element line = (Element) title.item(0);
                    System.out.println("Title: " + getCharacterDataFromElement(line));
                    NodeList des = element.getElementsByTagName("description");
                    line = (Element) des.item(0);
                    System.out.println("Des: " + getCharacterDataFromElement(line));
            } catch (Exception e) {
                e.printStackTrace();
        public String getCharacterDataFromElement(Element e) {
            Node child = e.getFirstChild();
            if (child instanceof CharacterData) {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            return "?";
    }And here's the error message:
    org.xml.sax.SAXParseException: Teckenkonverteringsfel: "Malformed UTF-8 char -- is an XML encoding declaration missing?" (radnumret kan vara f�r l�gt).
        at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)
        at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1072)
        at org.apache.crimson.parser.InputEntity.isXmlDeclOrTextDeclPrefix(InputEntity.java:914)
        at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:1183)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:653)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
        at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
        at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
        at getrss.RSSDocument.<init>(RSSDocument.java:25)
        at getrss.Main.main(Main.java:25)

    I read files from the web, but there is a XML tag
    with the encoding attribute in the RSS file.If you are quite sure that you have an encoding attribute set to ISO-8859-1 then I expect that your RSS file has non-ISO-8859-1 character though I thought all bytes -128 to 127 were valid ISO-8859-1 characters!
    Many years ago I had a problem with an XML file with invalid characters. I wrote a simple filter (using FilterInputStream) that made sure that all the byes it processed were ASCII. My problem turned out to be characters with value zero which the Microsoft XML parser failed to process. It put the parser in an infinite loop!
    In the filter, as each byte is read you could write out the Hex value. That way you should be able to find the offending character(s).

Maybe you are looking for

  • Stock on posting date GL wise

    dear sir, can i have the transaction code for stock on posting date GL wise. IN MB5B THERE IN NO FIELD WITH GL AND IN MB5B THERE IS NO POSTING DATE

  • A different way to deal with "unknown" user after upgrade from Tiger.

    It's a known issue that doing upgrade and install or archive and install from Tiger to Leopard, produces a lot of folders with "unknown" group in their "get info" panel. This has to do with a different group structure in Tiger and Leopard. In Tiger,

  • Intercompany transaction in mm

    Hi, Can we use cross company code transaction in Material Management? How? Thanks, Avaduz

  • I tunes wont install ive tried a lot of things

    Im trying to update itunes. at first it immediatly claimed that drive J:\ was non existent. i fixed this in command prompt and it now starts to install just fine for about 5 mins when it tells me that drive J is too long. What the **** is it talking

  • How to call Siebel wsdl from EBS R12

    Dear Gurus, Is there anyone knows how to call Siebel wsdl file generated from EBS R12, directly without using middleware/weblogic ? Please help Thanks in advance Eldin