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);
}

Similar Messages

  • Parsing xml with dom4j - cannot find jar file

    Hi,
    I'm using Jdeveloper 10g and tomcat 5.5.9. I have a servlet which calls a java class (ParseXML.java) that trys to parse an xml string using dom4j. A snippet of ParseXML.java...
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    public class ParseXML  {
    public ParseXML(String xml) {
              this.XML_STRING = xml;
         public String parse() {
              SAXReader reader = new SAXReader();
              Document document = null;
              try  {
                   document = reader.read(XML_STRING);
                   } catch (DocumentException de)  {
                   return de.getMessage();
              } catch (Exception e) {
                   return e.getMessage();
                   return "The xml root value is: " + document.getRootElement().getName();
    } I've downloaded the dom4j 1.6.1 jar and put it on the project class path (specified in the jdev project proerties), and my code also compiles ok. But when i try to instantiate ParseXML from my servlet i get a runtime exception:
    javax.servlet.ServletException: Servlet execution threw an exception
    root cause
    java.lang.NoClassDefFoundError: org/dom4j/DocumentException
         arcims.GetMapServlet.doPost(GetMap.java:45)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802I'm not sure if this is a class path issue or something else; i've checked and rechecked the classpath and nothing seems amiss.
    Suggestions, anyone?

    Question: Is it really necessary to use a
    StringReader if my xml document is not saved to disk?
    I get XML_STRING from a web service, convert it into
    a xml document so i can manipulate/parse it, but then
    i don't save the document, i just discard it. How
    does my system's default character set affect string
    manipulations that i do within my java app?Your system's default charset doesn't have anything to do with string manipulations, if by that you mean substrings and concatenations of strings. It is used when you convert strings to bytes and bytes to strings. If your string contains a character that can't be handled by your default charset, then converting that string to bytes will put ? in place of that character. Converting those bytes back to a string will leave the ? as is. Thus your string has been changed.
    Also converting the string to bytes can have bad results, because the first thing the XML parser does is to convert the bytes back to a string, using the charset declared in the XML. If this charset is different from your system's default, then your XML may be corrupted by this process if it contains characters that are encoded differently in the two charsets. The typical example of this is European accented letters like �, which are encoded differently in ISO-8859-1 or Windows-1252 (most people's default charsets) and UTF-8 (the default XML charset).
    Besides, converting the string to bytes just so it can be immediately converted back to a string is rather wasteful.

  • Xmlparser.parse fails when parsing xml with dtd

    Has anybody used successfully called xmlparser.parse in PL/SQL
    to parse an xml file with a dtd? When I try I get the following
    error:
    ERROR at line 1:
    ORA-20100: Error occurred while parsing: Invalid argument
    ORA-06512: at "SYS.XMLPARSER", line 22
    ORA-06512: at "SYS.XMLPARSER", line 69
    ORA-06512: at line 6
    When I remove the dtd reference from the xml file it works.
    (I posted this question yesterday but no responses, so I'm
    trying again...)
    Thanks - Dana

    Please see:
    http://forums.oracle.com/forums/message.jsp?id=617954
    for the solution. Thanks.

  • Problem parsing XML with schema when extracted from a jar file

    I am having a problem parsing XML with a schema, both of which are extracted from a jar file. I am using using ZipFile to get InputStream objects for the appropriate ZipEntry objects in the jar file. My XML is encrypted so I decrypt it to a temporary file. I am then attempting to parse the temporary file with the schema using DocumentBuilder.parse.
    I get the following exception:
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element '<root element name>'
    This was all working OK before I jarred everything (i.e. when I was using standalone files, rather than InputStreams retrieved from a jar).
    I have output the retrieved XML to a file and compared it with my original source and they are identical.
    I am baffled because the nature of the exception suggests that the schema has been read and parsed correctly but the XML file is not parsing against the schema.
    Any suggestions?
    The code is as follows:
      public void open(File input) throws IOException, CSLXMLException {
        InputStream schema = ZipFileHandler.getResourceAsStream("<jar file name>", "<schema resource name>");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
          factory.setAttribute(JAXP_SCHEMA_SOURCE, schema);
          builder = factory.newDocumentBuilder();
          builder.setErrorHandler(new CSLXMLParseHandler());
        } catch (Exception builderException) {
          throw new CSLXMLException("Error setting up SAX: " + builderException.toString());
        Document document = null;
        try {
          document = builder.parse(input);
        } catch (SAXException parseException) {
          throw new CSLXMLException(parseException.toString());
        }

    I was originally using getSystemResource, which worked fine until I jarred the application. The problem appears to be that resources returned from a jar file cannot be used in the same way as resources returned directly from the file system. You have to use the ZipFile class (or its JarFile subclass) to locate the ZipEntry in the jar file and then use ZipFile.getInputStream(ZipEntry) to convert this to an InputStream. I have seen example code where an InputStream is used for the JAXP_SCHEMA_SOURCE attribute but, for some reason, this did not work with the InputStream returned by ZipFile.getInputStream. Like you, I have also seen examples that use a URL but they appear to be URL's that point to a file not URL's that point to an entry in a jar file.
    Maybe there is another way around this but writing to a file works and I set use File.deleteOnExit() to ensure things are tidied afterwards.

  • 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 Parsing Error: no element found Location: jar:file:///C:/Program%20Files/Mozilla%20Firefox/chrome/toolkit.jar!/content/global/netError.xhtml Line Number 1, Column 1:

    Accidentally clicked on "Allow for Safe Networks Only" and saved it. When launching Firefox, this error: XML Parsing Error: no element found
    Location: jar:file:///C:/Program%20Files/Mozilla%20Firefox/chrome/toolkit.jar!/content/global/netError.xhtml
    Line Number 1, Column 1:
    I have uninstalled and reinstalled, changed to a new profile, nothing works. I have looked at Options - Network - No Proxy
    Please help as I love Firefox

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • Validating xml with dtd

    Hi,
             I have found a piece of code through google, to validate an xml file with an external dtd file. which is
               function validateDocument()
                    xmlDocumentObject = new ActiveXObject("microsoft.XMLDOM")
                    xmlDocumentObject.onreadystatechange = changeHandler
                    xmlDocumentObject.load('C:\\My.xml')
                function changeHandler()
               and for that we need to a import i.e  #import "C:\WINDOWS\system32\msxml4.dll"
              here when i try to import "msxml4.dll" in Acrobat javascript (js) file, it is giving error, application exits.
               How can i import dll in Acrobat javascript to get some functionality, or if not
              What someother way to achieve this(To validate xml with dtd file).
             This is totally making me crazy, please someone help me on this issue.
    thanks in advance.

    thanks Leonard,
             But my problem is i have an xml(i created that using acrobat javascript)and a dtd file, i want validate xml file with that dtd, using acrobat or some other way.  How can i validate xml with dtd, please help me.

  • Persisting unexplained errors when parsing XML with schema validation

    Hi,
    I am trying to parse an XML file including XML schema validation. When I validate my .xml and .xsd in NetBeans 5.5 beta, I get not error. When I parse my XML in Java, I systematically get the following errors no matter what I try:
    i) Document root element "SQL_STATEMENT_LIST", must match DOCTYPE root "null".
    ii) Document is invalid: no grammar found.
    The code I use is the following:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    My XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- Defining the SQL_STATEMENT_LIST element -->
    <xs:element name="SQL_STATEMENT_LIST" type= "SQL_STATEMENT_ITEM"/>
    <xs:complexType name="SQL_STATEMENT_ITEM">
    <xs:sequence>
    <xs:element name="SQL_SCRIPT" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <!-- Defining simple type ApplicationType with 3 possible values -->
    <xs:simpleType name="ApplicationType">
    <xs:restriction base="xs:string">
    <xs:enumeration value="DawningStreams"/>
    <xs:enumeration value="BaseResilience"/>
    <xs:enumeration value="BackBone"/>
    </xs:restriction>
    </xs:simpleType>
    <!-- Defining the SQL_SCRIPT element -->
    <xs:element name="SQL_SCRIPT" type= "SQL_STATEMENT"/>
    <xs:complexType name="SQL_STATEMENT">
    <xs:sequence>
    <xs:element name="NAME" type="xs:string"/>
    <xs:element name="TYPE" type="xs:string"/>
    <xs:element name="APPLICATION" type="ApplicationType"/>
    <xs:element name="SCRIPT" type="xs:string"/>
    <!-- Making sure the following element can occurs any number of times -->
    <xs:element name="FOLLOWS" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    and my XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Document : SQLStatements.xml
    Created on : 1 juillet 2006, 15:08
    Author : J�r�me Verstrynge
    Description:
    Purpose of the document follows.
    -->
    <SQL_STATEMENT_LIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.dawningstreams.com/XML-Schemas/SQLStatements.xsd">
    <SQL_SCRIPT>
    <NAME>CREATE_PEERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE PEERS (
    PEER_ID           VARCHAR(20) NOT NULL,
    PEER_KNOWN_AS      VARCHAR(30) DEFAULT ' ' ,
    PRIMARY KEY ( PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITIES_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITIES (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    COMMUNITY_KNOWN_AS VARCHAR(25) DEFAULT ' ',
    PRIMARY KEY ( COMMUNITY_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITY_MEMBERS (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    PEER_ID VARCHAR(20) NOT NULL,
    PRIMARY KEY ( COMMUNITY_ID, PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_PEER_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE PEERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITIES_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITIES IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITY_MEMBERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_VIEW</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE VIEW COMMUNITY_MEMBERS_VW AS
    SELECT P.PEER_ID, P.PEER_KNOWN_AS, C.COMMUNITY_ID, C.COMMUNITY_KNOWN_AS
    FROM PEERS P, COMMUNITIES C, COMMUNITY_MEMBERS CM
    WHERE P.PEER_ID = CM.PEER_ID
    AND C.COMMUNITY_ID = CM.COMMUNITY_ID
    </SCRIPT>
    <FOLLOWS>CREATE_PEERS_TABLE</FOLLOWS>
    <FOLLOWS>CREATE_COMMUNITIES_TABLE</FOLLOWS>
    </SQL_SCRIPT>
    </SQL_STATEMENT_LIST>
    Any ideas? Thanks !!!
    J�r�me Verstrynge

    Hi,
    I found the solution in the following post:
    Validate xml with DOM - no grammar found
    Sep 17, 2003 10:58 AM
    The solution is to add a line of code when parsing:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    The errors are gone !!!
    J�r�me Verstrynge

  • How to Parse XML with SAX and Retrieving the Information?

    Hiya!
    I have written this code in one of my classes:
    /**Parse XML File**/
              SAXParserFactory factory = SAXParserFactory.newInstance();
              GameContentHandler gameCH = new GameContentHandler();
              try
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse(recentFiles[0], gameCH);
              catch(javax.xml.parsers.ParserConfigurationException e)
                   e.printStackTrace();
              catch(java.io.IOException e)
                   e.printStackTrace();
              catch(org.xml.sax.SAXException e)
                   e.printStackTrace();
              /**Parse XML File**/
              games = gameCH.getGames();And here is the content handler:
    import java.util.ArrayList;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    class GameContentHandler extends DefaultHandler
         private ArrayList<Game> games = new ArrayList<Game>();
         public void startDocument()
              System.out.println("Start document.");
         public void endDocument()
              System.out.println("End document.");
         public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
         public void characters(char[] ch, int start, int length) throws SAXException
              /**for (int i = start; i < start+length; i++)
                   System.out.print(ch);
         public ArrayList<Game> getGames()
              return games;
    }And here is the xml i am trying to parse:<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <Database>
         <Name></Name>
         <Description></Description>
         <CurrentGameID></CurrentGameID>
         <Game>
              <gameID></gameID>
              <name></name>
              <publisher></publisher>
              <platform></platform>
              <type></type>
              <subtype></subtype>
              <genre></genre>
              <serial></serial>
              <prodReg></prodReg>
              <expantionFor></expantionFor>
              <relYear></relYear>
              <expantion></expantion>
              <picPath></picPath>
              <notes></notes>
              <discType></discType>
              <owner></owner>
              <location></location>
              <borrower></borrower>
              <numDiscs></numDiscs>
              <discSize></discSize>
              <locFrom></locFrom>
              <locTo></locTo>
              <onLoan></onLoan>
              <borrowed></borrowed>
              <manual></manual>
              <update></update>
              <mods></mods>
              <guide></guide>
              <walkthrough></walkthrough>
              <cheats></cheats>
              <savegame></savegame>
              <completed></completed>
         </Game>
    </Database>I have been trying for ages and just can't get the content handler class to extract a gameID and instantiate a Game to add to my ArrayList! How do I extract the information from my file?
    I have tried so many things in the startElement() method that I can't actually remember what I've tried and what I haven't! If you need to know, the Game class instantiates with asnew Game(int gameID)and the rest of the variables are public.
    Please help someone...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    OK, how's this?
    public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
              current = "";
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
              try
                   if(qualifiedName.equals("Game") || qualifiedName.equals("Database"))
                        {return;}
                   else if(qualifiedName.equals("gameID"))
                        {games.add(new Game(Integer.parseInt(current)));}
                   else if(qualifiedName.equals("name"))
                        {games.get(games.size()-1).name = current;}
                   else if(qualifiedName.equals("publisher"))
                        {games.get(games.size()-1).publisher = current;}
                   etc...
                   else
                        {System.out.println("ERROR - Qualified Name found in xml that does not exist as databse field: " + qualifiedName);}
              catch (Exception e) {} //Ignore
         public void characters(char[] ch, int start, int length) throws SAXException
              current += new String(ch, start, length);
         }

  • Urgent help for processing XML stream read from a JAR file

    Hi, everyone,
         Urgently need your help!
         I am reading an XML config file from a jar file. It can print out the result well when I use the following code:
    ===============================================
    InputStream is = getClass().getResourceAsStream("conf/config.xml");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line;
    while ((line = br.readLine()) != null) {
    System.out.println(line); // It works fine here, which means that the inputstream is correct
    // process the XML stream I read from above
    NodeIterator ni = processXPath("//grid/gridinfo", is);
    Below is the processXPath() function I have written:
    public static NodeIterator processXPath(String xpath, InputStream byteStream) throws Exception {
    // Set up a DOM tree to query.
    InputSource in = new InputSource(byteStream);
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    dfactory.setNamespaceAware(true);
    Document doc = dfactory.newDocumentBuilder().parse(in);
    // Use the simple XPath API to select a nodeIterator.
    System.out.println("Querying DOM using " + xpath);
    NodeIterator ni = XPathAPI.selectNodeIterator(doc, xpath);
    return ni;
    It gives me so much errors:
    org.xml.sax.SAXParseException: The root element is required in a well-formed doc
    ument.
    at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213
    at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XM
    LDocumentScanner.java:570)
    at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.endO
    fInput(XMLDocumentScanner.java:790)
    at org.apache.xerces.framework.XMLDocumentScanner.endOfInput(XMLDocument
    Scanner.java:418)
    at org.apache.xerces.validators.common.XMLValidator.sendEndOfInputNotifi
    cations(XMLValidator.java:712)
    at org.apache.xerces.readers.DefaultEntityHandler.changeReaders(DefaultE
    ntityHandler.java:1031)
    at org.apache.xerces.readers.XMLEntityReader.changeReaders(XMLEntityRead
    er.java:168)
    at org.apache.xerces.readers.UTF8Reader.changeReaders(UTF8Reader.java:18
    2)
    at org.apache.xerces.readers.UTF8Reader.lookingAtChar(UTF8Reader.java:19
    7)
    at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.disp
    atch(XMLDocumentScanner.java:686)
    at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
    canner.java:381)
    at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.
    java:195)
    at processXPath(Unknown Source)
    Thank you very much!
    Sincerely Yours
    David

    org.xml.sax.SAXParseException: The root element is required in a well-formed document.This often means that the parser can't find the document. You think it should be able to find the document because your test code could. However if your test code was not in the same package as your real (failing) code, your test is no good because getResourceAsStream("conf/config.xml") is looking for that file name relative to the package of the class that contains that line of code.
    If your test code wasn't in any package, put a slash before the filename and see if that works.

  • Parsing xml with namespaces

    Hi
    I have to parse a xml file with 2 namespaces.
    The file looks like as follows
    <AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
    <BB xmlns="">
    <Id>262</Id>
    <Time>2011-03-10T13:55:00.000-06:00</Time>
    <Indicator>true</Indicator>
    </BB>
    </AA>
    i tried following 3 methods to parse this xml file but failed
    PROCEDURE LOAD_XML
    IS
    l_clob := ' <<Above XML Content Here >>';
    lv_root CONSTANT VARCHAR2(1000) := '/AA/BB'; /* Tried lv_root CONSTANT VARCHAR2(1000) := 'AA/BB' with all the three methods */
    /* Method 1 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/"';
    /* Method 2 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/" xmlns=""';
    /*Method 3 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/"/xmlns=""';
    BEGIN
    l_parser := dbms_xmlparser.newParser;
    BEGIN
    dbms_xmlparser.parseClob(l_parser, l_clob);
    END;
    l_doc := dbms_xmlparser.getDocument(l_parser);
    -- Free resources associated with the CLOB and Parser now they are no longer needed.
    dbms_xmlparser.freeParser(l_parser);
    l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),lv_root,lv_namespaces );
    FOR cur_rec IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
    l_n := dbms_xmldom.item(l_nl, cur_rec);
    lv_rows_inserted_cnt := lv_rows_inserted_cnt + 1;
    dbms_output.put_line('I am Here');
    lv_rows_processed_cnt := lv_rows_inserted_cnt;
    dbms_xmldom.freeDocument(l_doc);
    l_clob := null;
    dbms_output.put_line(lv_rows_processed_cnt||' Rows Parsed ');
    END LOAD_XML ;
    Every time zero rows are being parsed and it's not going into the for loop at all.
    How to parse these kind of multiple namespaces (Especially default and unassigned namespaces ) ?
    Thanks
    Pramod

    As Anton showed, you don't need namespace if you directly access target node with the descendant axis.
    However, I guess it's a simplified example so if you need it in a more complex case, this will do it :
    DECLARE
    l_clob clob := '<AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
    <BB xmlns="">
    <Id>262</Id>
    <Time>2011-03-10T13:55:00.000-06:00</Time>
    <Indicator>true</Indicator>
    </BB>
    </AA>';
    lv_root       CONSTANT VARCHAR2(1000) := '/ns1:AA/BB/*';
    lv_namespaces CONSTANT VARCHAR2(1000) := 'xmlns:ns1="http://XX.com/provider/C/D/E/F/2010/"';
    l_parser dbms_xmlparser.Parser := dbms_xmlparser.newParser;
    l_doc    dbms_xmldom.DOMDocument;
    l_nl     dbms_xmldom.DOMNodeList;
    l_n      dbms_xmldom.DOMNode;
    lv_rows_inserted_cnt  NUMBER := 0;
    lv_rows_processed_cnt NUMBER;
    BEGIN
    dbms_xmlparser.parseClob(l_parser, l_clob);
    l_doc := dbms_xmlparser.getDocument(l_parser);
    dbms_xmlparser.freeParser(l_parser);
    l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc), lv_root, lv_namespaces);
    FOR cur_rec IN 0 .. dbms_xmldom.getLength(l_nl) - 1
    LOOP
       l_n := dbms_xmldom.item(l_nl, cur_rec);
       lv_rows_inserted_cnt := lv_rows_inserted_cnt + 1;
       dbms_output.put_line(dbms_xmldom.getNodeValue(dbms_xmldom.getFirstChild(l_n)));
    END LOOP;
    lv_rows_processed_cnt := lv_rows_inserted_cnt;
    dbms_xmldom.freeDocument(l_doc);
    dbms_output.put_line(lv_rows_processed_cnt||' Rows Parsed ');
    END;
    /If you're on version 10.2 (or +), maybe you'll find easier to use XMLTable instead :
    SQL> select *
      2  from xmltable(
      3    xmlnamespaces('http://XX.com/provider/C/D/E/F/2010/' as "ns1"),
      4    '/ns1:AA/BB'
      5    passing xmltype('<AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
      6  <BB xmlns="">
      7  <Id>262</Id>
      8  <Time>2011-03-10T13:55:00.000-06:00</Time>
      9  <Indicator>true</Indicator>
    10  </BB>
    11  </AA>')
    12    columns id        number                   path 'Id',
    13            time      timestamp with time zone path 'Time',
    14            indicator varchar2(10)             path 'Indicator'
    15  )
    16  ;
            ID TIME                                              INDICATOR
           262 10/03/11 13:55:00,000000 -06:00                   true

  • Deploying an application with existing library as jar file created with ANT

    Hello All,
    I am having some trouble with a web application I am deploying to Tomcat. I have an custom library that works perfectly as a jar file included in the lib directory if I include all the jars that that library depends on into the lib directory also. What I would like to do is bundle the required jar files into my libraries jar file, but it failes to work when I do that.
    Any thoughts? Does Tomcat prevent this?
    I am using ANT to create my jar file, but when I look at the contents of my jar file it includes all the requested directories.
    My build.xml looks like this:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <project name="myapp" basedir="." default="jar">
    <property name="classes.dir" value="./classes"/>
    <property name="jar.dir" value="."/>
    <property name="java_lib.dir" value="../../../../../Program Files/Java/lib"/>
    <target name="jar">
    <jar destfile="${jar.dir}/${ant.project.name}.jar">
    <fileset dir="classes"/>
    <fileset dir="${java_lib.dir}" includes="jai_codec.jar.jar"/>
    <fileset dir="${java_lib.dir}" includes="xercesImpl.jar"/>
    <fileset dir="${java_lib.dir}" includes="mysql-connector-java-3.1.8-bin.jar"/>
    <fileset dir="${java_lib.dir}" includes="xmlParserAPIs.jar"/>
    <fileset dir="${java_lib.dir}" includes="mlibwrapper_jai.jar"/>
    <fileset dir="${java_lib.dir}" includes="xml-apis.jar"/>
    <fileset dir="${java_lib.dir}" includes="jai_core.jar"/>
    </jar>
    </target>
    <target name="run" depends="jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
    </target>
    <target name="clean-build" depends="jar"/>
    <target name="main" depends="run"/>
    </project>
    Like I said...it includes these jar files in my jar file, but will not function properly with my tomcat app. If I exclude these jar files and include them seperately then everything works.
    NOTE: I do not access any of these libraries directly from any servlets, only from my classes.
    Thanks,
    J-Rod

    This probably isn't posted on the correct forum. This JVM forum is for discussing issues related to running java in an Oracle database using the OJVM, Oracle's embedded java VM. Possibly you are trying to use OJVM through JDEV but that isn't clear from your post and I don't believe that the error you are reporting would occur in that case. If it did or if you are in fact trying to run client java via JDEV the problem would be a JDEV rather than OJVM issue and so the JDEV forum,
    JDeveloper and ADF
    is the correct one to use.

  • Does IE/Firefox browser validate a give XML with DTD

    Hi,
    The following is my XML with an internal DTD and below that is the css
    <?xml version="1.0" ?>
    <!DOCTYPE INVENTORY
    <!ELEMENT INVENTORY (BOOK)+ >
    <!ELEMENT BOOK (NAME,PRICE)>
    <!ELEMENT NAME (#PCDATA)>
    <!ELEMENT PRICE (#PCDATA)>
    <!ELEMENT IMAGE EMPTY>
    >
    <?xml-stylesheet type="text/css" href="Inventory01.css"?>
    <INVENTORY>
    <BOOK>
         <NAME> 101 Thins to lie </NAME>
         <PRICE> 9494.03</PRICE>
         <IMAGE> TEST </IMAGE>
    </BOOK>
    <BOOK>
         <NAME> iT nEVER Gets Better </NAME>
         <PRICE> 44.43</PRICE>
    </BOOK>
    </INVENTORY>The following is the CSS file refered above.
    BOOK
         display:block;
         margin-top:12pt;
         font-size:10pt
    NAME
         display:block;
         margin-top:12pt;
         font-weight:bold;
         font-style:italic;
    PRICE
         display:block;
         margin-left:15pt;
    }I was expecting the browser to validate my XML and give me an error. Please tell me if the browsers validate XMLs? If yes, is there any issue with the above code.
    Thanks.
    Regards,
    Technoz

    I was expecting the browser to validate my XML and
    give me an error. Please tell me if the browsers
    validate XMLs?Try this experiment: Set up an XML that doesn't validate against its internal DTD. Then load it into a browser to see if the browser validates it or not.
    Oh wait, didn't you already try that experiment? What did you find out?

  • Problem with HelpSet in a jar file

    In our application, the content of the html-pages of the help
    set is not displayed ( the index is ! ) if we put the help set
    in a jar file.
    Withour using a jar file, it works fine.
    The problem appeared with all JavaHelp versions I tried (up to 2.0 beta)
    and using JREs >= 1.3.1_0x. Its funny that it works fine with 1.3.1
    Capitels in the file names are NOT the problem.
    Can anybody help me ?
    Do I have to include somethingh in the MANIFEST.MF file of
    the jar ? If so, what ?

    Check the case of the file names such as map.jhm File names are not case sensitive when in a jar file.

  • Problem with creation of a jar file from inside a java program

    Hi,
    I am trying to create a jar file at runtime from within a java program.
    I am able to create a jar file just fine using:
    String[] jarArgs = new String[3];
    jarArgs[0] = "cvf";
    jarArgs[1] = "C:\temp\myjar.jar";
    jarArgs[2] = "C:\temp\this";
    sun.tools.jar.Main main1 = new sun.tools.jar.Main(System.out, System.err, "jar");
    main1.run(jarArgs);However, when I look at the jar it puts the absolute path to the files inside such as:
    C:\temp\this\is\my\package\Class.class
    instead of only this\is\my\package\Class.class
    When running the jar command from the command line it works just fine and I have the relative paths in my jar file.
    Does anyone have any experience with this and could help me out?
    Thanks in advance
    Edited by: mruf on Apr 11, 2008 1:51 AM

    Shouldn't jarArgs[2] = "-C C:\temp\this"

Maybe you are looking for