Content of generated XML document to variable - Oracle ...

Hello everybody,
here is sample code which generates XML document:
* This is a sample application program which is built using the
* classes generated by the XML DTD Class Generator. The External DTD
* File "Widl.dtd" or the XML document which "Widl.xml" which is compliant
* to Widl.dtd is used to generate the classes. The application
* SampleMain.java is used to generate the classes which takes the DTD
* or XML document as input parameters to generate classes.
import oracle.xml.classgen.CGNode;
import oracle.xml.classgen.CGDocument;
import oracle.xml.classgen.DTDClassGenerator;
import oracle.xml.classgen.InvalidContentException;
import oracle.xml.parser.v2.DTD;
public class TestWidl
public static void main (String args[])
try
WIDL w1 = new WIDL();
DTD dtd = w1.getDTDNode();
w1.setNAME("WIDL1");
w1.setVERSION(WIDL.VERSION_1_0);
SERVICE s1 = new SERVICE("Service1", "Service_URL");
s1.setINPUT("File");
s1.setOUTPUT("File");
BINDING b1 = new BINDING("Binding1");
b1.setTYPE(BINDING.TYPE_INPUT);
BINDING b2 = new BINDING("Binding2");
b2.setTYPE(BINDING.TYPE_OUTPUT);
VARIABLE v1 = new VARIABLE("Variable1", VARIABLE.NULLOK_FALSE);
v1.setTYPE(VARIABLE.TYPE_STRING);
v1.setUSAGE(VARIABLE.USAGE_INTERNAL);
v1.setVALUE("value");
VARIABLE v2 = new VARIABLE("Variable2", VARIABLE.NULLOK_TRUE);
v2.setTYPE(VARIABLE.TYPE_STRING1);
v2.setUSAGE(VARIABLE.USAGE_HEADER);
VARIABLE v3 = new VARIABLE("Variable3", VARIABLE.NULLOK_FALSE);
v3.setTYPE(VARIABLE.TYPE_STRING2);
v3.setUSAGE(VARIABLE.USAGE_FUNCTION);
v3.setMASK("mask");
CONDITION c1 = new CONDITION("CRef1", "CMatch1");
c1.setSERVICE("Service1");
c1.setTYPE(CONDITION.TYPE_SUCCESS);
CONDITION c2 = new CONDITION("CRef2", "CMatch2");
c2.setTYPE(CONDITION.TYPE_RETRY);
CONDITION c3 = new CONDITION("CRef3", "CMatch3");
c3.setSERVICE("Service3");
c3.setTYPE(CONDITION.TYPE_FAILURE);
REGION r1 = new REGION("Region1", "Start", "End");
b1.addNode(r1);
b1.addNode(v1);
b1.addNode(c1);
b1.addNode(v2);
b2.addNode(c2);
b2.addNode(v3);
w1.addNode(s1);
w1.addNode(b1);
w1.addNode(b2);
w1.validateContent();
w1.print(System.out);
catch (Exception e)
System.out.println(e.toString());
e.printStackTrace();
I see the method w1.print(System.out) which shows content of xml to console. But how can I store xml to some String variable? Thank you in advance.
Jan :)

If there is a version of the "print" method that can write to a Writer, then:StringWriter sw = new StringWriter();
w1.print(sw);
String result = sw.toString();But if you can only write to an OutputStream then:ByteArrayOutputStream baos = new ByteArrayOutputStream();
w1.print(baos);
String result = new String(baos.toByteArray(), encoding);where "encoding" is a string containing the name of the encoding used to write the XML. Possibly you can control that via "w1.setENCODING(something)" or some other way.

Similar Messages

  • Urgetnt:Generate XML Document from Oracle Tables.

    Environment is :9i Release 2
    Requirement : Generate XML document from the data which is vailable in Oracle tables at client location.
    Could some body help me on how to get ahead on this.
    Thanks in advance,
    Kumar.

    Implimentation in PowerBuilder7(Source is experimental.. need optimization):
    kml_store = create datastore
    selectblob kml into :kml_result from (select get_kml(:querry_type,:tmp_querry_value,1) as kml from dual) using sqlca;
    if sqlca.sqlcode=100 then
    MessageBox("INFO","No data found");
    return false;
    end if
    if sqlca.sqlcode = -1 then
         MessageBox("INFO","Error in generating KMl file");
         return false
    end if
    li_FileNum = FileOpen("test.kml",StreamMode!, Write!, LockWrite!, Replace!);
    b_len=Len(kml_result)
    b_len=64244;
    /*inserting in file :)*/
    DO WHILE b_pos<=b_len
         s_pipe=String(BlobMid(kml_result,b_pos,i_str_len))
         ret = FileWrite(li_FileNum,s_pipe);
         s_pipe="";
         b_pos=b_pos+i_str_len;
    LOOP
    FileClose(li_FileNum);
    Message was edited by:
    user601564

  • How to compare the contents of two XML documents

    Hi all,
    I was trying to compare the contents of two xml documents, they are both validate for the same XML Schema. i was using the xmlunit to do this. but some how it doesn't work like what i have expected. for example:
    1.xml : <test><item>2</item><item>1</item></test>
    2.xml: <test><item>3</item><item>2</item><item>1</item></test>
    the result from XMLUnit is this two xmls are different, but it compares <item>2</item> with <item>3</item>, which i cannot find out where the real diiffs are.
    does anybody know how i can do this correct?
    best regards,
    tina

    I faced a similar problem in one of my projects and hence wrote my own comparator. Most comparators like ExamXML etc show XML as different if the nodes under a parent node occur in different seqeunce or a set of repeated nodes occur in different sequence. The comparator that I wrote gives you the flexibility to configure how to identify a node from a set of repeated nodes and is able to compare them successfully if they occur in any order. You can view the sample output at http://geocities.com/dheerendra_itbhu/TipsFromDheeru.html
    and contact me in case you need the source code.

  • How to validate generated XML-Document in Memory by XML-Schema?

    Hi all!
    I have the following problem:
    I am generating a Document using the DOM delivered with Xerces 2.6.2.
    Before I'll send the generated xml-document through network to another system I have to check with my xml-schema if the document is correct.
    In the DOM-FAQ I found an "example" trying to explain how it should work. But with this example the problems begin.
    I am creating my document with this method:
         public void createDocument() {
              myDOM = DOMImplementationImpl.getDOMImplementation();
              doc = myDOM.createDocument("", "documentData", null);
              root = doc.getDocumentElement();
              root.setAttribute(
                   "xmlns:xsi",
                   "http://www.w3.org/2001/XMLSchema-instance");
              //          root.setAttribute("xsi:noNamespaceSchemaLocation", "myScheme.xsd");
              domConfig = ((DocumentImpl) doc).getDomConfig();
              domConfig.setParameter(
                   "schema-location",
                   "file:///d:/workspace/XMLProject/WebContent/WEB-INF/myScheme.xsd");
              domConfig.setParameter("error-handler", new EHandler());
              domConfig.setParameter("validate", Boolean.TRUE);
         }In the line getting the domConfig, it is getting differeing to the example: The example is like this:
    import org.w3c.dom.Document;
    import org.w3c.dom.DOMConfiguration;
    import org.w3c.dom.ls.LSParser;
    Document document = builder.parseURI("data/personal-schema.xml");
    DOMConfiguration config = document.getConfig();
    config.setParameter("error-handler",new MyErrorHandler());
    config.setParameter("validate", Boolean.TRUE);
    document.normalizeDocument();They get the DOM-Configuration from the document-Object, but my document-Object has no "getConfig()" and only after type-casting I get a getDomConfig()-Method to get the configuration.
    Then I fill my document and call                
    ((DocumentImpl) doc).normalizeDocument();When I run my Application I get the following error:
    org.w3c.dom.DOMException: FEATURE_NOT_SUPPORTED: The parameter schema-location is recognized but the requested value cannot be set.
         at org.apache.xerces.dom.DOMConfigurationImpl.setParameter(Unknown Source)
         at xmlProject.createDocument(Convert.java:63)
         at xmlProject.Convert.main(Convert.java:154)I tried several ways to get the validation without success.
    The next question is how I should refer to my xml-schema (which path) and where to place it relative to my jar I will generate, because I will have no webserver I could place it on.
    Has anyone any experience with validating a document created and not placed on disc?
    I have also another question to SAX: I read, that it is reading a document without saving it in the memory. I think this means that if I am validating it by SAX it will be read once and for parsing it will be read a second time. If I would transfer the document over an tcp-connection, I only have the document once in my inputstream and after validation it would be consumed I think. But what can I parse then? Or did I missed a detail with the function of the SAX?
    Thank you for your help!
    Yours
    Christian

    static final String schemaSource = argv[0];
    static final String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    factory.setAttribute(JAXP_SCHEMA_SOURCE,
    new File(schemaSource));

  • Question about generate xml document

    Hi, I'm new to xml can anyone introduce me some tools to generate xml documents? or some faster way to generate xml documents.

    a good site for the info www.xml.com or www.oasis.org
    xml-spy is a good tool

  • Generate XML document

    Hi,
    My problem is about generating XML document. I'd like to be able to generate automaticaly (like what we can get at this kind of URL http://xdbserver:8080/oradb/USER/table_name) XML documents for any relational tables, I want the document being schema based and I want to store them in XDB in the repository.
    I do not really matter at the time the way the xml is generated (I just do not want that it takes hours). Is there a way to do that with PL/SQL package or with a java classes?
    Thanks in advance.
    Vlad

    1)I'm using this PL/SQL proc to create XML :
    (table_name in VARCHAR2)as --generation d'un fichier xml basé sur un schéma pour la table dont le nom est passé en paramètre
    qryCtx DBMS_XMLGEN.ctxHandle;
    result XMLType;
    begin
    qryCtx := dbms_xmlgen.newContext('SELECT * from VLAD.' || table_name);
    -- set the row header to be EMPLOYEE
    DBMS_XMLGEN.setRowTag(qryCtx, table_name);
    -- now get the result
    result := DBMS_XMLGEN.getXMLType(qryCtx,2); --2 for XMLSchema (1 for a DTD)
    --insertion de result dans la table tempo
    insert into tempo values(result);
    --close context
    DBMS_XMLGEN.closeContext(qryCtx);
    exception
    when others then
    dbms_output.put_line(TO_CHAR(sqlerrm));
    end;
    I saw in the doc that DBMS_XMLGEN.getXMLType(qryCtx,2) with the "2" was for schema but what does it do exactly, does it generate a schema against the table_name?
    2)I'd like to put the result which is XMLType in a XML file in the server, is there a way to do it with UTL FILE?
    Vlad

  • Generating XML Document by giving Object as input

    Hi all,
       I have to give some object as input for generating XML Document.Basing on the data in the object the XML file has to be generated.
    Please give me your guidance in this issue.
    Thanks&Regards
    Madhu

    Madhu,
    You may:
    1. Generate XML Document manually with DOM API
    2. Use some complex lib like implementation of <a href="http://java.sun.com/webservices/jaxb/">JAXB</a> with ad-hoc control over format.
    3. Use some simple library like <a href="http://xstream.codehaus.org/">XStream</a> with minimal format control.
    Valery Silaev
    EPAM Systems
    http://www.NetWeaverTeam.com

  • How do I  generate XML using internal variables in a procedure

    I know there is a way to generate XML inside a procedure by querying the database such as
    SELECT XMLELEMENT("Emp",
    XMLFOREST(e.employee_id, e.last_name, e.salary))
    "Emp Element"
    FROM employees e WHERE employee_id = 204;
    Emp Element
    <Emp>
    <EMPLOYEE_ID>204</EMPLOYEE_ID>
    <LAST_NAME>Baer</LAST_NAME>
    <SALARY>10000</SALARY>
    </Emp>
    What I have unsuccessfully been trying to do is to basically do the same thing except using internal variables like
    DECLARE
    l_keytype CONTACTINFO.KEYTYPE%TYPE;
    l_keyvalue CONTACTINFO.KEYVALUE%TYPE;
    l_pricetag CONTACTINFO.PRICATEG%TYPE;
    l_xmlout CLOB;
    BEGIN
    l_keytype := '1';
    l_keyvalue := '3333';
    l_pricetag := '10';
    SELECT XMLELEMENT("ParamSet", .........................this is line 13
    XMLFOREST(l_keytype as "keytype", l_keyvalue as "keyvalue", l_pricetag as "pricetag"))
    "ParamSet Element"
    INTO l_xmlout FROM DUAL;
    DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmlout);
    end;
    What I'd like it to generate is
    <ParamSet>
    <KEYTYPE>1 </KEYTYPE>
    <KEYVALUE>3333</KEYVALUE>
    <PRICETAG>100</PRICETAG>
    </ParamSet>
    But what I get is a compile error
    Error report:
    ORA-06550: line 13, column 19: (line 13 is SELECT XMLELEMENT("ParamSet", )
    PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got -
    ORA-06550: line 13, column 1:
    PL/SQL: SQL Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    Also, I've been told that one issue with XMLFOREST is that if the value is null it won't generate the XML for it. Not good. I will still need the XML even if it is empty. Please help.

    Darn, Marc beat me. Here was my answer showing an alternative for returning an XMLType, since that is what the query returns as he said.
    DECLARE
       l_keytype    VARCHAR2(5);
       l_keyvalue   VARCHAR2(5);
       l_pricetag   VARCHAR2(5);
       l_xmlout     CLOB;
       l_xmltype    XMLTYPE;
    BEGIN
       l_keytype := '1';
       l_keyvalue := '3333';
       l_pricetag := '10';
       SELECT XMLELEMENT("ParamSet",
                 XMLFOREST(l_keytype as "keytype",
                           l_keyvalue as "keyvalue",
                           l_pricetag as "pricetag")).getClobVal()
         INTO l_xmlout
         FROM DUAL;
       DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmlout);
       SELECT XMLELEMENT("ParamSet",
                 XMLFOREST(l_keytype as "keytype",
                           l_keyvalue as "keyvalue",
                           l_pricetag as "pricetag"))
         INTO l_xmltype
         FROM DUAL;
       DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmltype.getClobVal());
    end;Here is a link to Oracle's on-line documentation
    http://www.oracle.com/technetwork/indexes/documentation/index.html
    so that you can pick your version and search for XMLElement and XMLForest to see their difference as well as listening to us.

  • New to XML, need to generate XML document

    I have an existing application that uses an Oracle 9.2.0.3 database. An existing PL/SQL procedure generates a flat file interface using UTL_FILE. My task is to upgrade this procedure to generate an XML file and transform this XML file into different outputs (e.g. flat file interface, PDF file which I plan to use XSL Formatting Objects). My question is how should I generate the XML document from the PL/SQL procedure? Should I use the Oracle 9i SQL/XML capabilities? specifically xmlelement, etc? An if so should I also use UTL_FILE to generate the XML file? Your help will be appreciated.

    Williams,
    Do you want to generate an XML file from the data present in relational tables using PL/SQL ?
    In that case you can use XML SQL Utility(XSU).
    For more information on XSU click [url http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96621/adx23xsp.htm#1008317]here.
    Regards,
    Anupama
    [url http://otn.oracle.com/sample_code/]OTN Sample Code

  • Generate xml source file for Oracle Order Capture Print Quote

    Hi,
    I am new to xml and need to work on creating templates for Print Quote.
    I am trying to generate the xml source file for which I enabled the report in system administrator and set the output to XML and assigned to Quoting Reports responsiblity. I then assigned XML Report Publisher to the same responsiblity.
    I ran the report (Print Quote) and then I am trying to run the XML Report Publisher but I cannot get the request id in the list of values.
    I am able to generate xml source file for other reports like Printed Purchase Order etc.,
    The view output for the (Print Quote) report is as follows:
    <?xml version="1.0" ?>
    - <!-- Generated by Oracle Reports version 6.0.8.26.0
    -->
    <ASOPQTER />
    How do I get the xml source file? Or are there seeded templates that I can use to create more templates? Any help would be appreciated. Thanks Ravi

    Hi, I am in the same position - did this issue ever ger resolved by anyone. I have done a few XMLP reports successfully now using the Word add-in, but customising the Quote output differs from other standard reports.
    If you look at the data definition for Quote it is a 'dummy' definition and has no XML file attached. Does anyone know how I can get the XML format for the report output?
    Also the template uses XSL-FO ?!?!?! rather than RTF - not sure how to work with this, the Oracle docs are not very helpful in this regard either.
    Has anyone successfully managed to customise the Quote print report? Many thanks,
    Roger

  • Help - Inserting an XML document into a Oracle 8i Column (CLOB Type)

    Hi JavaGurus,
    I am looking for a simple java code which will take my XML document as input and insert the same into a Oracle 8i database's column which is of type CLOB.
    Insert statement won't work and I can not use SQL Loader.
    Any one?
    JK

    Maybe you can adapt some of the code in Oracle's "LOB Datatype" example, which is a complete working program that stores and retrieves BLOBs and CLOBs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html

  • Can not generate XML Document Template

    I have the below class
    public class MyHome implements Serializable {
    ArrayList rooms;
    //getter/setter methods here
    When I right click mouse and select "Generate XML Template Document", I got the error
    Some fields could not be generated to the XML template
    c:\e200\dv900\java\classes\java\util\ArrayList.class (The system cannot find the path specified)
    Do you have any idea?

    Not with the info given...
    Which jdev version?
    Where do I find this menu, as I don't see it?
    Timo

  • Generating XML document

    Hello, All!
    I have some questions about XML in Oracle 9.2
    For examle, I have a query such as:
    select to_clob(
    ((XMLElement("MSG" , XMLAttributes('EXPOPR' as "FORMAT",
         '1' as "SENDER",
                             '2' as "RECIPIENT",
                             to_char(SYSDATE, 'YYYY.MM.DD HH24:MI:SS') as "TIME"
         ))) msg
    from dual
    MSG
    <MSG FORMAT="EXPOPR" SENDER="1" RECIPIENT="2" TIME="2004.10.04 10:23:16"></MSG>
    1) How I can get a full XML document from this result (add <?xml version ...> tag)? I know about SYS_XMLGen, but this function will add a <ROW> tag into XML, but I don't need this...
    Also, I can use concatenation of strings, but it is not interestring for me...
    2) How I can get the string without enclose tag </MSG>:
    <MSG FORMAT="EXPOPR" SENDER="1" RECIPIENT="2"
    TIME="2004.10.04 10:23:16" />
    Thank for help.

    There is a new function XMLRoot that will be released as part of 10gR2 for this. In the mean time string concatenation is the only solution..
    The following works in 10gR1
    create or replace function XMLROOT (XML XMLType,
    target varchar2 default NULL,
    data varchar2 default NULL,
    CHARSET varchar2 default 'UTF-8')
    return XMLType deterministic
    is
    tempCLOB clob;
    tempXML XMLtype;
    PI VARCHAR2(256);
    begin
    PI := '<?' || target || ' ' || data || '?>';
    select xmlparse(DOCUMENT '<?xml version="1.0" encoding="UTF-8"?>' || PI || XML.getClobVal() WELLFORMED)
    into tempXML
    from dual;
    return tempXML;
    end;
    In 9.2 it would need to be something like this
    create or replace function XMLROOT (XML XMLType,
    target varchar2 default NULL,
    data varchar2 default NULL,
    CHARSET varchar2 default 'UTF-8')
    return XMLType deterministic
    is
    tempCLOB clob;
    tempXML XMLtype;
    PI VARCHAR2(256);
    begin
    PI := '<?' || target || ' ' || data || '?>';
    select xmltype('<?xml version="1.0" encoding="UTF-8"?>' || PI || XML.getClobVal(),0,1,1)
    into tempXML
    from dual;
    return tempXML;
    end;
    /

  • Inserting PI into generated XML document

    Can anyone tell me how to insert processing instructions into an XML document generated using the xmlcg generated classes? I understand that I can create a PI using the Document::createProcessingInstruction() method but how do I add it as a sibling to the root element? Any insight in this regard will be really appreciated.

    Your question is not very clear.
    Do you want to know How to insert an element into an XML document?
    Answer: I can see you already know how to do it. You have added the element using addContent()
    or do you want to know How to display the XML in a tidy format?
    Answer: to view the XML in a properly formatted style you can you the Format class. A very basic way of viewing the XML would be:
       * Prints the Document to the specified file.
       * @param doc
       * @param filename
       * @param formatting
      public static void printDocToFile(Document doc, String strFileName,
          boolean formatting)
        XMLOutputter xmlOut = null;
        if (!formatting)
          xmlOut = new XMLOutputter();
        } else
          Format prettyFormat = Format.getPrettyFormat();
          prettyFormat.setOmitEncoding(false);
          prettyFormat.setOmitDeclaration(false);
          xmlOut = new XMLOutputter(prettyFormat);
        try
          if (doc != null)
            FileWriter writer = new java.io.FileWriter(strFileName, true);
            xmlOut.output(doc, writer);
            writer.flush();
            writer.close();
          } else
            System.out.println("Document is null.");
        catch (Exception ex)
          System.out.println(ex);
      }

  • Generate XML file from an Oracle Database Table

    Hello All,
    I want to generate a xml file from an Oracle Database table which contains a blob column.
    Can somebody give pointers on this please.
    Thanks in advance
    Sulakshana

    Use the DBMS_XMLGEN package.

Maybe you are looking for

  • LAN performance is really slow

    Generally I get a maximum transferrate of 1.7Mb per second. The valet M20 that is rated upto 300 megabits per second which should deliver upto 37.5 megabytes per second (at maximum) perfomance over a lan (1mb = 8mbps).   Considering the two computers

  • Why does safari 5.1.3 reset after quit, after updating to Mac OS X 10.7.3?

    I updated to 10.7.3 today and I set Safari up. I turned off my computer and later when I turned it back on Safari was completely reset and all the settings I had set were gone. This also happens when I quit or exit out of Safari too. What is the prob

  • How to see the group membership for a user in oidadmin

    how to see the group membership for a user in oidadmin? I see the memberships in oiddas, but I would like to know if its possible to see them in oidadmin? Thanks.

  • My 15" Macbook pro gives me a "USB over current notice," NOTHING PLUGGED IN

    My 15" Macbook pro always gives me a "USB over current notice" on startup and VERY frequently throughout use (I'm talking every 5 minutes) without ANYTHING plugged in. My computer is ****** up, and will often freeze without being charged, (and thats

  • What am I doing wrong - size issue

    Need some advice...as usual! I designed a site on my 17" monitor and set the margins to 0 and table to 100%. However when I look at it on different screens it looks rubbish...big gap at the bottom of the page with the design cramp at the top. I wonde