Parsing an XML doc with unavailable entity (DTD)

Hi all,
I am trying to parse an XML file (web.xml) that has the following DOCTYPE in the head of the document:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp">When the parser starts, it will look for the DTD on the Sun site, however my work firewall blocks access to this so I get an exception when parsing.
To resolve this, I have tried to force the parser to look for a local copy of the DTD instead of the Sun site but to no avail. I still get the same error but don't know why it wont look at the local DTD.
Here is my code:
* InterceptingXml.java
* Created on 04 April 2006, 15:58
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package org.xmldemos;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
* @author CS781RJ
public class InterceptingXml
    /** Creates a new instance of InterceptingXml */
    public InterceptingXml() { }
    public void parse(String filename)
        try
            // Create an XML parser
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            // Install the entity resolver
            builder.setEntityResolver(new MyResolver());
            // Parse the XML file
            Document doc = builder.parse(new File(filename));
        catch (SAXException e) { e.printStackTrace(); }
        catch (ParserConfigurationException e) { e.printStackTrace(); }
        catch (IOException e) { e.printStackTrace(); }
        catch (Exception e) { e.printStackTrace(); }
    public class MyResolver implements EntityResolver
        // This method is called whenever an external entity is accessed
        // for the first time.
        public InputSource resolveEntity(String publicId, String systemId)
            try
                System.out.println("publicId: " + publicId + " systemId: " + systemId);
                // Wrap the systemId in a URI object to make it convenient
                // to extract the components of the systemId
                URI uri = new URI(systemId);
                System.out.println("URI scheme: " + uri.getScheme());
                System.out.println("URI scheme specific: " + uri.getSchemeSpecificPart());
                // Check if external source is a file
                if ("http".equals(uri.getScheme()))
                    String filename = uri.getSchemeSpecificPart();
                    filename = "file:/C:/web-app_2_3.dtd";
                    InputSource isrc = new InputSource(new FileReader(filename));
                    return isrc;
            catch (URISyntaxException e) { }
            catch (IOException e) { }
            // Returning null causes the caller to try accessing the systemid
            return null;
    public static void main(String[] args)
        InterceptingXml ixml = new InterceptingXml();
        ixml.parse("c:\\web.xml");
}And here is the exception:
init:
deps-jar:
compile-single:
run-single:
publicId: -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN systemId: http://java.sun.com/dtd/web-app_2_3.dtd
URI scheme: http
URI scheme specific: //java.sun.com/dtd/web-app_2_3.dtd
java.net.UnknownHostException: java.sun.com
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
        at java.net.Socket.connect(Socket.java:507)
        at java.net.Socket.connect(Socket.java:457)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
        at sun.net.www.http.HttpClient.New(HttpClient.java:287)
        at sun.net.www.http.HttpClient.New(HttpClient.java:299)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:973)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:905)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:872)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:282)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1021)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:172)
        at org.xmldemos.InterceptingXml.parse(InterceptingXml.java:45)
        at org.xmldemos.InterceptingXml.main(InterceptingXml.java:88)
BUILD SUCCESSFUL (total time: 18 seconds)I have noticed that return isrc; does not get executed even though the debugger steps to the line above it.
Thanks in advance.
Riz

What's the point of all that code in your EntityResolver? Would the code work just as well if the DTD didn't even exist? Then do this:public InputSource resolveEntity(String publicId, String systemId)
            return new InputSource(new StringReader(""));
        }However if you really do need to redirect to a local copy of the DTD then consider this:catch (IOException e) { }can be a real barrier to understanding in the case that an IOException is thrown. At least print a stacktrace. And: the FileReader class wants a file name in its constructor, not a URI. And in this code:String filename = uri.getSchemeSpecificPart();
filename = "file:/C:/web-app_2_3.dtd";you could write this instead:String filename = "file:/C:/web-app_2_3.dtd";which would be both shorter and easier to understand.

Similar Messages

  • Still problems serializing xml-docs with xml-parser for java v2.0.2.7

    Hi !
    I'm using the Oracle XML Parser 2.0.2.7.0 and get some problems when serializing the XMLDocument.
    In one class (DOMOut) I parse a xml-file with the oracle.xml.parser.v2.DOMParser, then obtain the XMLDocument and write it to System.out
    In another class (DOMIn) I fetch the XMLDocument from System.in, search for a given Element and print it's TextValue (if existing) to System.out
    That is where the error occurs.
    I get the XMLDocument from System.in but the returning NodeList from doc.getElementsByTagName() is empty. [nl.getLength()==0] even if it shouldn't be.
    Look at this code and output:
    [DOMOut]
    DOMParser parser = new DOMParser();
    parser.parse(url);
    XMLDocument doc = (XMLDocument)parser.getDocument();
    ObjectOutputStream out = new ObjectOutputStream(System.out);
    out.writeObject(doc); out.flush();
    [DOMIn]
    ObjectInputStream in = new ObjectInputStream(System.in);
    XMLDocument doc = (XMLDocument)in.readObject();
    doc.print(System.out);
    NodeList nl = doc.getElementsByTagName("Name");
    System.out.println("Length of NodeList: "+nl.getLength());
    if (nl.getLength()==0)
    System.out.println(argv[0] + ": not in this document!");
    else {
    XMLNode node = (XMLNode) nl.item(nl.getLength()-1);
    System.out.println(node.getNodeName() + ": " + (node.getFirstChild()).getNodeValue());
    This is the relevant code.
    I javac both classes and then do this:
    java DOMOut xmltestfile.xml > xx
    java DOMIn Name < xx
    And get this as output:
    <?xml version = '1.0'?>
    <!DOCTYPE course [
    <!ELEMENT course (Name,Dept,Instructor,Student)>
    <!ELEMENT Name ((#PCDATA)*)*>
    <!ELEMENT Dept ((#PCDATA)*)*>
    <!ELEMENT Instructor (Name)>
    <!ELEMENT Student (Name)*>
    ]>
    <course>
    <Name>Calculus</Name>
    <Dept>Math</Dept>
    <Instructor>
    <Name>Jim Green</Name>
    </Instructor>
    <Student>
    <Name>Jack</Name>
    <Name>Mary</Name>
    <Name>Paul</Name>
    </Student>
    </course>
    Length of NodeList: 0
    Name: not in this document!
    Has anyone an idea?
    If I do all this stuff without serializing it works.
    If I do not search for argv[0], but the string "Name" it fails.
    If I do search for "*" it works fine!
    I'm very confused could anybody please help me a bit??
    Stefan.
    [[email protected]]

    The link has been fixed. You will go to the v2 download page
    now. Sorry for the inconvience.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    Renilton Oliveira (guest) wrote:
    : I didn't find the file for version 2.0.0.0 as well.
    : Renilton
    : Andrei Filimonov (guest) wrote:
    : : I tried to download XML Parser for Java v2 it seems that
    only
    : v
    : : 1.0.1.4 is available. Could you please give an exact URL for
    : v2
    : : download?
    : : Andrei Filimonov
    : : Oracle XML Team wrote:
    : : : The Oracle XML v2 parser is now available for download
    here
    : as
    : : : an early beta release and is written in Java. It features
    : an
    : : : improved architecture over the Oracle XML v1 parser and
    has
    : : : shown better performance on small to large XML documents.
    : It
    : : : will also be able to format the XML document according to
    a
    : : : stylesheet, having integrated an XSLT processor.
    : : : Version 2 of the XML Parser for Java, besides
    incorporating
    : an
    : : : XSLT processor, has been re-architected from version 1.
    This
    : : has
    : : : resulted in a number of changes to the class names
    : especially
    : : : those that support Namespaces. See v2changes.txt and
    : the .diff
    : : : difference files in the sample directory.
    : : : Oracle XML Team
    : : : http://technet.oracle.com
    : : : Oracle Technology Network
    null

  • Has anybody tried creating and validating a XML doc with XML Schema?

    Hi,
    Has anybody tried creating and validating a XML doc with XML Schema?

    With XMLBeans, an XML document may be created from and validated with an XML schema.

  • Generete xml doc with dtd form

    Hi,
    I am trying to generate xml doc based on dtd kind format.
    I use following code to get my xml doc is ok based on dtd like
    -----------dtd file---------------
    <!ELEMENT client_data (client_job*, person*)>
    <!ELEMENT client_job (job_cd, job_title?, primary_responsibilities?, grade_cd?, br_job_cd, eeo_job_group_id, effective_date?, end_date?)>
    <!ATTLIST client_job errMsg CDATA #IMPLIED>
    <!ATTLIST client_job deleteFlag ( Y | N ) 'N'>
    <!ELEMENT job_cd (#PCDATA)>
    <!ELEMENT job_title (#PCDATA)>
    <!ELEMENT primary_responsibilities (#PCDATA)>
    <!ELEMENT br_job_cd (#PCDATA)>
    <!ELEMENT eeo_job_group_id (#PCDATA)>
    -----------------end dtd--------------
    OracleXMLQuery qry = new OracleXMLQuery(conn, sql);
    qry.setRowsetTag("client_data");
    qry.setRowIdAttrName(null);
    // qry.useNullAttributeIndicator(true);
    qry.useLowerCaseTagNames();
    qry.setRowTag("client_job");
    xmlDocToReturn = qry.getXMLDOM();
    But if my dtd like following, i.g. has tree level, and data from multiple tables, the above code doesn't work for thes case
    --------------tree level dtd----------------
    <!ELEMENT person (person_name)>
    <!ATTLIST person person_id CDATA #REQUIRED>
    <!ATTLIST person hire_date CDATA #IMPLIED>
    <!ATTLIST person effective_date CDATA #IMPLIED>
    <!ATTLIST person end_date CDATA #IMPLIED>
    <!ELEMENT person_name (formatted_name*, given_name*, prefered_given_name?, middle_name?, family_name*, affix*)>
    <!ELEMENT formatted_name EMPTY>
    <!ATTLIST formatted_name type ( presentation | legal | sortOrder) 'presentation'>
    <!ELEMENT given_name (#PCDATA)>
    <!ELEMENT prefered_given_name (#PCDATA)>
    <!ELEMENT middle_name (#PCDATA)>
    <!ELEMENT family_name (#PCDATA)>
    <!ATTLIST family_name primary ( true | false | undefined ) 'undefined'>
    -----------------end dtd -------------------
    I try to use XMLDocumentFragment to create xml doc and appendChild , but the xml doc is not the format of the dtd required. Can you give me a Java sample?
    Thanks in advance.
    Yan

    Why don't you use XSLT?

  • Update passed in XML doc with pl/sql xmldom

    Hi,
    I have an xml document that is passed in through a stored procedure as CLOB. I'm trying to use the XMLParser and XMLDOM to add an additional node
    The XML looks something like the following
    <rowset>
    <row>
    <firstname>john</firstname>
    </row>
    <row>
    <firstname>jane</firstname>
    </row>
    </rowset>
    I need to loop through each of <mynames> nodes and then add another node <lastame> so it looks like the following
    <rowset>
    <row>
    <firstname>john</firstname>
    <lastame>smith</lastame>
    </row>
    <row>
    <firstname>jane</firstname>
    <lastame>smith</lastame>
    </row>
    </rowset>
    I have the following code
    parseClob XMLPARSER.Parser;
    newNames XMLDOM.DOMDocument;
    tempNode XMLDOM.DOMNode;
    mye xmldom.domelement;
         item_text xmldom.DOMText;
    numofrows number;
         nodeList xmldom.DOMNodeList;
         newnode xmldom.domnode;
    parseClob := xmlparser.newParser;
    XMLPARSER.parseClob(parseClob,names);
    newNames := XMLPARSER.getDocument(parseClob);
    XMLPARSER.freeParser(parseClob);
    nodeList := xslprocessor.selectNodes(xmldom.makeNode(newNames), '//rowset/row');
    numOfRows := xmldom.getlength(nodeList)-1;
    for i in 0..numOfRows LOOP
    newnode := xmldom.item(nodeList, i);
              --create the new node
    mye := xmldom.createElement(newName, 'lastname');
    --add it to the new node   
    tempNode := xmldom.appendChild(newnode, xmldom.makeNode(mye));
    --update the text in the lastname   
    item_text := xmldom.createTextNode(newNames, 'smith');
    tempNode := xmldom.appendChild(tempNode, xmldom.makeNode(item_text));
    end loop;
    what happens is that when i write out the newnode xml out to a buffer i see the <lastname> tag
    but when i write out the newNames xml out to a buffer after the loop is finished the <lastname> tag is
    missing. like it didn't update the newNames xml
    I've seen lots of example on how to create an XML document with the DOM from scratch but nothing about updating
    an passed in xml document. any help would be appreciated

    Updatexml is reference in Oracle 9i, I'm sorry i should have mentioned that I am using oracle 8i. Is there something you can use in oracle 8i?

  • 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.

  • Is it possible to create indexes & use them on xml docs with namespaces?

    I have put an XML doc in a BDBXML container which looks like this:
    *<ns1:note xmlns:ns1="http://www.testsch.org/ns">*
    *<ns1:to>Eric</ns1:to>*
    *<ns1:from>Brendan</ns1:from>*
    *<ns1:msg>How r u?</ns1:msg>*
    *</ns1:note>*
    Now, I am creating an index on the element "to", as:
    addIndex "ns1" "to" node-element-equality-string
    Though the index has been shown as getting created using the listIndexes command, if I lookup that index with the following command:
    lookupIndex node-element-equality-string "ns1" "to"
    the output is:
    *0 objects returned for eager index lookup 'node-element-equality-string'*
    Whereas, if I do the whole procedure without the namespaces in the document & the commands, the result is fine:
    *1 object returned for eager index lookup 'node-element-equality-string'*
    Can someone please tell me whether using namespaces, the indexes can be created or not? If yes, how?
    Thanks,
    Dev
    Edited by: user11871332 on Sep 7, 2009 3:53 PM

    Hi Dev,
    When using XML, the prefix for the namespace is really just syntactic sugar. The actual namespace in your example is "http://www.testsch.org/ns", and that's the value that you need to use when creating your index:
    addIndex "http://www.testsch.org/ns" "to" node-element-equality-stringJohn

  • Create XML docs with hierarchy of tags and attr defined in databaste tables

    Hi,
    My problem is a little unique one. I want the ability to define the structure of the XML document (i.e. the hierarchy of element tags and attribute names) in the database tables. The values of tags and attributes will also be populated at runtime in tables.
    Then write some generic API that reads the structure of the XML document through the database tables and spits out an XML document based on this structure and values stored in the tables.
    So, basically, I want the tag names and values both to be values in the database rather than the tag names being the columns in database tables.
    With this I should be able to have one procedure/function that can serve the purpose of creating XML documents with different structures by just specifying that structure in the form of database tables.
    Almost all the Oracle XML utilities I read about, create XML docs based on a SQL query with tag names being columns in the database tables. Any help will be highly appreciated.
    Thanks,
    Monika

    Which database release are you using...
    The computed constructors feature of XQuery may help.
    -Mark

  • Adding an XML doc with repeating tags

    Hello,
    Can anyone tell me how I take an XML document with a tag that can appear from 0-N times and map it to a database table? I am currently using a supertable and then using triggers to move data to the appropriate spot but am stuck on how to map tags that don't correspond 1-1.
    My structure is like
    <product>
    <name>
    <model>
    <cost>
    <feature>* (0-N)
    <spec>* (0-N)
    </product>
    Thanks.
    null

    Do a getElementsByTagName on a node and do a
    insert on each node found.

  • XML doc with multiple namespaces

    Hi,
    a little stupid question...
    Is it possible to get a xml file that assigns two different namespaces and I don't want to use a prefix?
    example:
    xml doc uses namespace xmlns:a="someuri" and xmlns:b="otheruri"
    <?xml version="1.0" encoding="UTF-8"?>
    <Root xmlns="someuri" xmlns:b="otheruri">
    <test/>
    <b:rest/>
    </Root>
    Some way to get prefix b out of it?
    Thanx

    okay, it was a stupid question...
    solution:
    <?xml version="1.0" encoding="UTF-8"?>
    <Root xmlns="someuri" xmlns:b="otheruri">
    <test/>
    <rest xmlns="otheruri"/>
    </Root>

  • 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

  • Applet parsing XML doc with schema

    I'm trying to parse (org.apache.xerces.parsers.SAXParser) an xml document and validate it with a schema file. I'm having a little difficulty understanding how the schemaLocation (as specified in the xml file) is used by the parser. I'm trying to use a relative path....but what is it relative to???
    In the xml file I specify the schemaLocation as...
    xsi:schemaLocation="http://tempuri.org/DeviceDefinition.xsd ./Configuration/DeviceDefinition.xsd"
    The directory structure I'm using is...
    ProjectX/applet.jar
    ProjectX/applet.html
    ProjectX/Configuration/DeviceDefinition.xml
    ProjextX/Configuration/DeviceDefinition.xsd
    It's my understanding that when working with an applet the paths are a relative to the directory where the applet is installed - ProjectX in this case. Yet when I use the above defined schemaLocation I get the following error:
    [Fatal Error] :0:0: File "file:///C:/Documents and Settings/dnelson/Desktop/Configuration/DeviceDefinition.xsd" not found.
    It seem to be using my user.dir as a starting point for the relative path. Does anyone know why this happens???
    What's the proper way to specify the schemaLocation??

    xerces hates spaces in uri. so try encoding the url or get rid of the spaces

  • How to parse an XML document with oracle8i

    Has anyone a good link or an example how to decode and store an XML document into an oracle8i database.
    I' ve found only good things for oracle9i.
    Thank you
    Roger

    Here is an example of parsing xml taken fro Oracle8i 8.1.7 xdk.
    This one uses external OS files to pase, but could be easily converted to
    use CLOB or VARCHAR2 string for parsing XML documents.
    IF you wanted to use CLOB to store and manipulate xml documents you can use XMLParser and XMLDom
    packages along with the DBMS_LOB package to do that.
    -- This file demonstates a simple use of the parser and DOM API.
    -- The XML file that is given to the application is parsed and the
    -- elements and attributes in the document are printed.
    -- The use of setting the parser options is demonstrated.
    set serveroutput on;
    create or replace procedure domsample(dir varchar2, inpfile varchar2,
    errfile varchar2) is
    p xmlparser.parser;
    doc xmldom.DOMDocument;
    -- prints elements in a document
    procedure printElements(doc xmldom.DOMDocument) is
    nl xmldom.DOMNodeList;
    len number;
    n xmldom.DOMNode;
    begin
    -- get all elements
    nl := xmldom.getElementsByTagName(doc, '*');
    len := xmldom.getLength(nl);
    -- loop through elements
    for i in 0..len-1 loop
    n := xmldom.item(nl, i);
    dbms_output.put(xmldom.getNodeName(n) || ' ');
    end loop;
    dbms_output.put_line('');
    end printElements;
    -- prints the attributes of each element in a document
    procedure printElementAttributes(doc xmldom.DOMDocument) is
    nl xmldom.DOMNodeList;
    len1 number;
    len2 number;
    n xmldom.DOMNode;
    e xmldom.DOMElement;
    nnm xmldom.DOMNamedNodeMap;
    attrname varchar2(100);
    attrval varchar2(100);
    begin
    -- get all elements
    nl := xmldom.getElementsByTagName(doc, '*');
    len1 := xmldom.getLength(nl);
    -- loop through elements
    for j in 0..len1-1 loop
    n := xmldom.item(nl, j);
    e := xmldom.makeElement(n);
    dbms_output.put_line(xmldom.getTagName(e) || ':');
    -- get all attributes of element
    nnm := xmldom.getAttributes(n);
    if (xmldom.isNull(nnm) = FALSE) then
    len2 := xmldom.getLength(nnm);
    -- loop through attributes
    for i in 0..len2-1 loop
    n := xmldom.item(nnm, i);
    attrname := xmldom.getNodeName(n);
    attrval := xmldom.getNodeValue(n);
    dbms_output.put(' ' || attrname || ' = ' || attrval);
    end loop;
    dbms_output.put_line('');
    end if;
    end loop;
    end printElementAttributes;
    begin
    -- new parser
    p := xmlparser.newParser;
    -- set some characteristics
    xmlparser.setValidationMode(p, FALSE);
    xmlparser.setErrorLog(p, dir || '/' || errfile);
    xmlparser.setBaseDir(p, dir);
    -- parse input file
    xmlparser.parse(p, dir || '/' || inpfile);
    -- get document
    doc := xmlparser.getDocument(p);
    -- Print document elements
    dbms_output.put('The elements are: ');
    printElements(doc);
    -- Print document element attributes
    dbms_output.put_line('The attributes of each element are: ');
    printElementAttributes(doc);
    -- deal with exceptions
    exception
    when xmldom.INDEX_SIZE_ERR then
    raise_application_error(-20120, 'Index Size error');
    when xmldom.DOMSTRING_SIZE_ERR then
    raise_application_error(-20120, 'String Size error');
    when xmldom.HIERARCHY_REQUEST_ERR then
    raise_application_error(-20120, 'Hierarchy request error');
    when xmldom.WRONG_DOCUMENT_ERR then
    raise_application_error(-20120, 'Wrong doc error');
    when xmldom.INVALID_CHARACTER_ERR then
    raise_application_error(-20120, 'Invalid Char error');
    when xmldom.NO_DATA_ALLOWED_ERR then
    raise_application_error(-20120, 'Nod data allowed error');
    when xmldom.NO_MODIFICATION_ALLOWED_ERR then
    raise_application_error(-20120, 'No mod allowed error');
    when xmldom.NOT_FOUND_ERR then
    raise_application_error(-20120, 'Not found error');
    when xmldom.NOT_SUPPORTED_ERR then
    raise_application_error(-20120, 'Not supported error');
    when xmldom.INUSE_ATTRIBUTE_ERR then
    raise_application_error(-20120, 'In use attr error');
    end domsample;
    show errors;

  • XML docs with BLOB

    I know it is possible to save an XML document into a BLOB field. However, can anyone tell me if it is possible to pass a BLOB in an XML document. What I mean is can I have an XML document structured as follows? Is so, where can I find the syntax. We receive XML orders via XSQL page and would like to store this data in the DB.
    <xml version="1.0">
    <books>
    <book>
    <isbn>032541251</isbn>
    <title>How to Program in XML</title>
    <cover>****.jpg file with picture of book that can be store in BLOB ****</cover>
    <exceprt>****.PDF or MS Word .DOC of prelude for example****</except>
    </book>
    </books>
    </xml>
    Any help would be appreciated

    Refer
    http://builder.com.com/5100-31-5075709.html
    The XMLType may also be used.
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html

  • Calling web service with utl_dbws and parsing the xml result with Xpath

    I'm invoking a web service from the database(10.2.0.2.0) using sys.utl_dbws and all is working well. After executing response := sys.utl_dbws.invoke(call_, request); I execute dbms_output.put_line(substr(response.getstringval(),1,1500)); which results with:
    <refCursor10gProcessResponse xmlns="http://xmlns.oracle.com/refCursor10g">
    <result xmlns="http://xmlns.oracle.com/refCursor10g">
    <Row xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/ADM/SERVICES/GETST/">
    <Column name="C_ID" sqltype="VARCHAR2">20292</Column>
    <Column name="AYR" sqltype="VARCHAR2">2002</Column>
    <Column name="EDT" sqltype="VARCHAR2">2002-06-13</Column>
    <Column name="ETUS" sqltype="VARCHAR2">O</Column>
    <Column name="PC" sqltype="NUMBER">537</Column>
    <Column name="SG" sqltype="VARCHAR2"/>
    <Column name="VD" sqltype="VARCHAR2">Y</Column>
    <Column name="VR" sqltype="VARCHAR2">R</Column>
    <Column name="TS" sqltype="VARCHAR2">31</Column>
    <Column name="D" sqltype="VARCHAR2">I</Column>
    <Column name="T" sqltype="VARCHAR2">1</Column>
    <Column name="P" sqltype="VARCHAR2"/>
    <Column name="MT" sqltype="VARCHAR2">2</Column>
    <Column name="PTAT" sqltype="VARCHAR2"/>
    </Row>
    </result>
    </refCursor10gProcessResponse>
    How do I parse out just the value 20292 of Column name="C_ID" using xpath? I've tired but I don't think i have the xpath set up correctly:
    dbms_output.put_line(response.extract('//result/Row/Column/child::text)','xmlns="http://xmlns.oracle.com/refCursor10g"').getstringval());
    Error messgae is:
    ORA-30625: method dispatch on NULL SELF argument is disallowed
    ORA-06512: at "ADM.CONSUME_WEB_SERVICES", line 439
    ORA-06512: at 3
    Thanks

    Tried getting by the attribute but I don't think I have the format correct:
    dbms_output.put_line(response.extract('//result/Row/Column@C_ID/child::text()','xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/ADM/SERVICES/GETST"').getstringval());
    Here's the full soap response envelope:
    <env:Envelope
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
    <refCursor10gProcessResponse xmlns="http://xmlns.oracle.com/refCursor10g">
    <result xmlns="http://xmlns.oracle.com/refCursor10g">
    <Row xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/ADM/SERVICES/GETST/">
    <Column name="C_ID" sqltype="VARCHAR2">20292</Column>
    <Column name="AYR" sqltype="VARCHAR2">2002</Column>
    <Column name="EDT" sqltype="VARCHAR2">2002-06-13</Column>
    <Column name="ETUS" sqltype="VARCHAR2">O</Column>
    <Column name="PC" sqltype="NUMBER">537</Column>
    <Column name="SG" sqltype="VARCHAR2"/>
    <Column name="VD" sqltype="VARCHAR2">Y</Column>
    <Column name="VR" sqltype="VARCHAR2">R</Column>
    <Column name="TS" sqltype="VARCHAR2">31</Column>
    <Column name="D" sqltype="VARCHAR2">I</Column>
    <Column name="T" sqltype="VARCHAR2">1</Column>
    <Column name="P" sqltype="VARCHAR2"/>
    <Column name="MT" sqltype="VARCHAR2">2</Column>
    <Column name="PTAT" sqltype="VARCHAR2"/>
    </Row>
    </result>
    </refCursor10gProcessResponse>
    </env:Body>
    </env:Envelope>
    Any thoughts?

Maybe you are looking for