Best class to use to cache an XML document

Hello all,
I have an utility class representing an XML document, used withing a web application. This document shall be cached in the session since within a request and during the sessions I read it often and to several other things like XPath and XSLT.
But I am having problems due to this Bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6322678
and keep bad file descriptor errors due to these stream "specialities". There is a standard way of using cached+precompiled XSL templates and I wonder if there is a similar things for XML documents.
So I need an internal variable in my class containing the raw XML document - so using streams is not an ideal solution in regards of the bug - i am getting "bad file descriptor" errors from time to time.
I am playing with the idea of storing the XML document within a simple String and create the required Class from it for the according operations like XPath evaluation and XSL transformation. But I think that is quite more resource hungry than reading the XML document from the filesystem each time...
Has anyone some hints on how to keep an XML document in memory internally?
Thanks and regards,
Timo

Rehi,
So, everything works really fine! Thanks. As promised, here some examples
with bad indentations etc...:
Doing XSL transformation:
import java.io.StringWriter;
import org.w3c.dom.Document;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.Templates;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
TransformerFactory tFac = TransformerFactory.newInstance();
Templates compiledXslt = tFac.newTemplates(sheet);
Transformer transformer = compiledXslt.newTransformer();
StringWriter sw = new StringWriter();
StreamResult sr = new StreamResult(sw);
transformer.transform(new DOMSource(this.doc), sr);
System.err.println(sw.toString());************************
Doing XPath was a surprise and was originally my problem (I called evaluate() with an InputStream that occassioannly failed), I tried also here with new DOMSource() what also failed although not being null or so... funny: evaluate() can directly be called w/ dom.Document:
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
(this.doc is a org.w3c.dom.Document)
public String getXPathEvaluationAsString(String expr) {
     try {
          XPath xp = XPathFactory.newInstance().newXPath();
          return (String)xp.evaluate(
               expr,
               this.doc,
               XPathConstants.STRING
     } catch(Exception e) {
          e.printStackTrace();
     return " ";
}Thanks and regards,
Timo

Similar Messages

  • UCCX 8 - Dramatic change in the Create File Document step that is used by the Create XML Document step in order to read an XML file

    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-priority:99;
    mso-style-qformat:yes;
    mso-style-parent:"";
    mso-padding-alt:0in 5.4pt 0in 5.4pt;
    mso-para-margin:0in;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-fareast-font-family:"Times New Roman";
    mso-fareast-theme-font:minor-fareast;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;
    mso-bidi-font-family:"Times New Roman";
    mso-bidi-theme-font:minor-bidi;}
    For the last 5 years (and in IPCC3.x/4.x,UCCX/5.x/7.x) I've used the same basic subflow to read a XML document that contains holiday dates where the queue should be closed.  I've re-used this script on 20+ client installs and it's always worked.  The structure of the script allows you to pass the path and filename of the XML document as parameters to the subflow. (The document is in the repository)
    I loaded this script in UCCX 8.0.2 recently and it crashed with a Java.IO error.  It looked like it was trying to read the file system directly and not the repository. (In the Linux appliance model this kind of makes sense but why is the step trying to read the file system directly?)
    So I open a TAC case (SR# 615243125) and TAC tells me that the method of using the Create File Document step is not supported anymore and that I should specify the filename directly in the Create XML Document step
    The problem that I see (aside from having to edit all my scripts that use XML files) is that the Create XML Document step is looking for the input to be a type DOCUMENT and not a type STRING.  This seems to imply that I have to hardcode the document in each script that I deploy for a customer.  When it was a string it was easy to construct the full file path from parameters and pass to the subflow.
    Questions to the group
    #1 Am I missing something here?
    #2  Do you assume that you'll be able to load a script that worked fine in UCCX 7 into UCCX 8 and that it should completely function when you're doing everything according to the step reference documentation.
    #3 Cisco didn’t document this in any way that I can find.
    #4 How can you use the Create XML Document step in a fashion that would let you construct the path of the file and the filename previously in the script so you could pass it to a subflow ?  It would seem this functionality has been killed in UCCX 8
    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-priority:99;
    mso-style-qformat:yes;
    mso-style-parent:"";
    mso-padding-alt:0in 5.4pt 0in 5.4pt;
    mso-para-margin:0in;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-fareast-font-family:"Times New Roman";
    mso-fareast-theme-font:minor-fareast;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;
    mso-bidi-font-family:"Times New Roman";
    mso-bidi-theme-font:minor-bidi;}
    (Background)
    Create File Document Step
    The input filename is a STRING, could be an explicit path and filename in the repository or a variable that represents that path and string
    The output of this step is a DOCUMENT to be used in the Create XML Document step
    The string FILE_FullPathHolidayFiles references  en_us\folderName\documentName.xml
    The document was properly uploaded into the repository only, NOT trying to directly read c:\foo\blah…
    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-priority:99;
    mso-style-qformat:yes;
    mso-style-parent:"";
    mso-padding-alt:0in 5.4pt 0in 5.4pt;
    mso-para-margin:0in;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-fareast-font-family:"Times New Roman";
    mso-fareast-theme-font:minor-fareast;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;
    mso-bidi-font-family:"Times New Roman";
    mso-bidi-theme-font:minor-bidi;}
    The create XML document input can only be a type DOCUMENT

    #1 Am I missing something here?
    You are mixing two different issues together here.
    The Create File Document step is indeed not needed or supported for creating an XML document. That is why there is a unique step; to trigger XML parsing within the MIVR subsystem.
    Accessing the file system is restricted to a single folder within the VOS model (i.e. 8.0+). This folder is not backed up, replicated, or cleaned up automatically. It was intended to give developers some FS access as a temporary swap location only.
    #2  Do you assume that you'll be able to load a script that
    worked fine in UCCX 7 into UCCX 8 and that it should completely
    function when you're doing everything according to the step reference
    documentation.
    Assume nothing; read the documentation and attend one of the dozens of partner training sessions that CCBU put on advising of the upcoming changes.
    #3 Cisco didn’t document this in any way that I can find.
    You're right, I guess, on the Create File vs. XML Document step. AFAIK Cisco never wrote a notice into the Step Reference Guide explicitly stating that you cannot use the Create File Document although the documentation seemed pretty clear to me without it. File system restrictions are documented in the 8.0 release notes.
    Scripting and Development Series: Volume 2, Editor Step ReferenceUse the Create XML Document step to create a logical document that maps a document to another document variable (where the document has already been pre-parsed as an XML document and is ready to be accessed by the Get XML Document Data step).Use this step before the Get XML Document Data step to obtain data from a document formatted using the Extensible Markup Language (XML).
    #4 How can you use the Create XML Document step in a fashion that would
    let you construct the path of the file and the filename previously in
    the script so you could pass it to a subflow ?  It would seem this functionality has been killed in UCCX 8
    No it hasn't; just concatinate a string to build the Source Document parameter the step needs. Example:  "DOC[" + myFilePath + "]"

  • What is the best way to handle duplicate in an XML document?

    I have an XML document that may contain duplicated nodes. I want to insert it to the DBXML database, so that the duplicated nodes are eliminated.
    What would be the best way (in term of performance) to do it?
    I thought of enforcing the uniqueness constraint and then insert the nodes one by one, so that I will get an exception from the database if the node is duplicated, but I may have more than 50000 nodes in the worst case, so I'm not sure if this is still a good way to do it.
    Can someone give me some suggestion on this?
    Thanks!

    Hi,
    I would suggest to reconsider building of your document so that it doesn't contain duplicates if you don't need them. And it doesn't have much to do with DB XML then.
    Also you could insert your document with duplicates and use XQuery Update facilities to delete undesirable nodes.
    Vyacheslav

  • Using parser to parse xml document

    Hi all:
    I have a xml document which has a root element and the a list of elements(same type) underneath it.
    My question is:
    Is there a restriction on the number of elements(same type) that you can extract from the Document?
    Thanks.
    Rino

    If you use DOM of JDOM, you will have a problem when you run out of system memory.
    If you use SAX, the parser will throw events with the required data for the current node (element, data, attribute). Once the event has been processed, the data is out of scope (unless you still hold a reference to it).
    If you use SAX, you are able to process each node without keeping the data from that node any longer than you like. Unless you have to have the entire document available, I would suggest using SAX.

  • How to use OAF transform sotred xml documents using XSLT...

    Does anyone have any experience using XSLT in OAF? Specifically, I have xml documents stored in a clob to which I wish to apply an XSLT transformation and then store the transformed documents back into the clob. Is there a way to apply an XSLT transformation using say BI-Publisher via OAF?

    "XML DIFF" are the keywords you can use to search for products that do this. Last time I looked there was a lot of XML Diff implementations, but none of them produced human-readable output that I really liked. I expect that's because XML diff is an easy thing for people to ask for but not an easy thing to do, given the considerable number of ways there are to change a document.

  • Use JAXP for creating XML document

    Hi,
    I have used JAXP to create a XML docuemnt. But when I use Jaxp to parse it, it returns parsing error ''null''.
    I open the XML document in XMLspy and save again, then it can be parsed.
    Any suggestion for that? Thanks a lot.

    Are there any differences between the version created with jaxp and the one with xmlspy? are you using the validating parser? if you aren't you might be having trouble with white space. just a guess.

  • Using JAXB to edit XML documents

    I am trying to understand how (and whether) JAXB can be used to make the following types of changes to an existing XML document. I know that I can EDIT an XML document using the set methods that are generated by JAXB (in conformance with the XML Schema), and then I create a Marshaller and marshall the root element object.
    However, I have not figured out how to do any of the following:
    (i) insert a new element
    (ii) delete an existing element
    (iii) reorder elements.
    Here is an excerpt from an XML document:
    <directory name="dir">
    <file name="file1"/>
    <file name="file2"/>
    <file name="file3"/>
    </directory>
    The order in which the file elements appear is significant.
    If I want to add a new file (file4), how would I do this? Where would it be added, at the end? What if I wanted to add it after file2?
    If I want to delete file1, I don't know how to do that.
    Finally, if I want to move file2 after file3, I don't know how to do that.
    It seems as though I need access to the underlying com.sun.xml.bind.util.ListImpl (or similar collection object), which holds the actual file elements when JAXB unmarshals the xml file. However, this seems dangerous and I have gotten a concurrent access exception while trying to do something like this. (Another problem has to do with iterators, where I can't iterate through a list and then make a change to the list w/o messing up the iterator.)
    If there are any technologies other than JAXB that might accomplish this, but that provide data binding, I would be happy to hear about it. (I could try SAX/DOM/JDOM/DOM4J or XSLT, I guess, but I like the data binding of JAXB.)

    As is typical for me, I answered my own questions.
    if you are outside of an iterator, you can simply use the:
    add(object)
    add(position,object)
    remove(object)
    methods of the List interface to add and remove elements from the list of elements.
    Also, if you use a ListIterator, you can call the add() and remove() methods of ListIterator while iterating through the list.
    In order to reorder elements in the list, use:
    Collections.swap(list,pos1,pos2). Why this method is not built into the List interface itself is beyond me. This was only added in 1.4, btw.

  • Use JDBC to Access XML Documents in Oracle XML DB

    Hi folks,
    From the Oracle XML DB Developer's Guide 10g Release 1 (10.1) Chapter 12 Java API for XMLType, it show several examples for how java application use JDBC to access xml in XMLDB:
    1. use getOPAQUE() on XMLTYPE table/column and then call XMLTYPE.createXML();
    2. use getCLOBVal()/getStringVal()/getBLOBVal() in SQL statement;
    3.use getObject on the result and cast directly to XMLType;
    Among these 3 options, which is supposed to be the fastest way? Any difference between thin and oci?
    I have run some tests about that and the result is the second option (with thin driver) is the fastest. It surprises me because I think oci should be faster than thin. Does the result make sense?
    Thanks.

    Have you tried to trace your sessions to see how much work is happening? Traces should give you quantifiable information on exact times and access paths to the data.
    Below is a link to an O'Reilly book excerpt on Java programming with JDBC. Slightly data, but may be of assistance.
    http://www.onjava.com/lpt/a//onjava/excerpt/oraclejdbc_19/index.html

  • How to use NodeIterator on an XML document

    I have been trying to create a NodeIterator using the following code:
    try
    FileInputStream inStream;
    Document doc;
    String xmlDocumentPath = "I have a real path here";
    inStream = new FileInputStream(xmlDocumentPath);
    DOMParser parser = new DOMParser();
    parser.parse(inStream);
    doc = parser.getDocument();
    Node root = doc.getDocumentElement();
    formInputFilter filter = new formInputFilter();
    DocumentTraversal traverse = (DocumentTraversal)doc;
    NodeIterator iter = traverse.createNodeIterator(root, NodeFilter.SHOW_ALL, filter, true);
    Node n = (Node)iter.nextNode();
    while (n != null)
    System.out.println(n.getNodeName());
    catch (Exception e)
    System.out.println(e.toString());
    When the nextNode method is executed I get an NPE. Looking in the iterator it shows the value of next as null when it is created. I have found a couple of code sources that all show this as the correct way to create a NodeIterator and I can't figure out what I am doing wrong. I have tried creating it with and without my filter and I still have the same problem. I had other code that could loop through the XML file that worked but the NodeIterator would be much simpler to use. Anyone have a suggestion.

    Using JDev 9.0.3.1, and with a C:\temp\test.xml file setup ahead of time, running the following program works for me just fine. How is yours different?
    package test;
    import java.io.FileInputStream;
    import oracle.xml.parser.v2.DOMParser;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.traversal.DocumentTraversal;
    import org.w3c.dom.traversal.NodeFilter;
    import org.w3c.dom.traversal.NodeIterator;
    public class Test {
      public static void main(String[] args) throws Throwable {
        Test t = new Test();
        t.test();
      void test() throws Throwable {
        String xmlDocumentPath = "c:\\temp\\test.xml";
        FileInputStream inStream = new FileInputStream(xmlDocumentPath);
        DOMParser parser = new DOMParser();
        parser.parse(inStream);
        Document doc = parser.getDocument();
        Node root = doc.getDocumentElement();
        MyNodeFilter filter = new MyNodeFilter();
        DocumentTraversal traverse = (DocumentTraversal)doc;
        NodeIterator iter = traverse.createNodeIterator(root, NodeFilter.SHOW_ALL, filter, true);
        Node n = null;
        while ((n = (Node)iter.nextNode()) != null) {
          System.out.println(n.getNodeName());
      class MyNodeFilter implements NodeFilter {
        public short acceptNode(Node n){
          return FILTER_ACCEPT;
    }

  • UTL_DBWS, XML Document as a parameter

    I'm struggling with using a fully formed xml document as a parameter to a web service.
    Using this code I'm able to connect to the web service and sans the arg1 argument everything works.
    When I as in the code below use xmltype.toStringValue() or xmltype.toClobValue() charachters like < and > is replaced with the html encoded version (&lt; and &gt;) which does'nt work very well with the recieving web service.
    All three parameters is defined as string on the recieving web service.
    I've been searching this forum and using google, but can't find any examples doing something like this.
    Any help or pointers appreciated.
    procedure forwardToQueue is
    svc_ sys.utl_dbws.service;
    call_ sys.utl_dbws.call;
    svc_qname sys.utl_dbws.qname;
    response sys.xmltype;
    request sys.xmltype;
    utMelding sys.xmltype;
    t1 sys.xmltype;
    t2 sys.xmltype;
    doc xmldom.DomDocument;
    fListe xmldom.DOMNodeList;
    tmpL xmldom.DOMNodeList;
    fElement xmldom.domNode;
    tmp xmldom.domNode;
    meldingId strliten;
    arg0_node xmldom.domnode;
    arg0_elmt xmldom.domelement;
    arg0_text xmldom.domtext;
    arg1_node xmldom.domnode;
    arg1_elmt xmldom.domelement;
    arg1_text xmldom.domtext;
    arg2_node xmldom.domnode;
    arg2_elmt xmldom.domelement;
    arg2_text xmldom.domtext;
    child_doc xmldom.domdocument;
    main_node xmldom.domnode;
    root_node xmldom.domnode;
    root_elmt xmldom.domelement;
    x sys.xmltype;
    c varchar2(32000);
    bs_chr strmax;
    l_service sys.UTL_DBWS.service;
    l_call sys.UTL_DBWS.call;
    l_result ANYDATA;
    l_wsdl_url strmax := 'http://salah-test.sismo.local:8080/SIMSEJB/SIMSFacadeBean?wsdl';
    l_namespace strmax := 'http://salah-test.sismo.local:8080/SIMSEJB/SIMSFacadeBean';
    l_service_qname sys.utl_dbws.qname;
    begin
    procName := 'hentQueue';
    pl('*************** '||procName||' ***************');
    svc_qname := sys.utl_dbws.to_qname(null, 'SIMSFacadeBeanService');
    svc_ := sys.utl_dbws.create_service(svc_qname);
    call_ := sys.utl_dbws.create_call(svc_);
    sys.utl_dbws.set_target_endpoint_address(call_, 'http://salah-test.sismo.local:8080/SIMSEJB/SIMSFacadeBean');
    sys.utl_dbws.set_property(call_, 'SOAPACTION_USE', 'TRUE');
    sys.utl_dbws.set_property(call_, 'SOAPACTION_URI', 'sendMessage');
    sys.utl_dbws.set_property(call_, 'OPERATION_STYLE', 'document');
    x := genererSvar;
    doc := xmldom.newDOMDocument;
    main_node := xmldom.makeNode(doc);
    root_elmt := xmldom.createelement(doc, 'q0:sendMessage');
    xmldom.setattribute(root_elmt, 'xmlns:q0', 'si.sims.intern.service');
    root_node := xmldom.appendChild(main_node, xmldom.makeNode(root_elmt));
    -- Adding arg 0 as a string
    arg0_elmt := xmldom.createelement(doc, 'arg0');
    arg0_node := xmldom.appendchild(root_node, xmldom.makenode(arg0_elmt));
    arg0_text := xmldom.createtextnode(doc, '2');
    arg0_node := xmldom.appendchild(arg0_node, xmldom.makenode(arg0_text));
                   -- Adding arg 1 as a string
    arg1_elmt := xmldom.createelement(doc, 'arg1');
    arg1_node := xmldom.appendchild(root_node, xmldom.makenode(arg1_elmt));
    arg1_text := xmldom.createtextnode(doc, x.getClobVal());
    arg1_node := xmldom.appendchild(arg1_node, xmldom.makenode(arg1_text));
    -- Adding arg 2 as a string
    arg2_elmt := xmldom.createelement(doc, 'arg2');
    arg2_node := xmldom.appendchild(root_node, xmldom.makenode(arg2_elmt));
    arg2_text := xmldom.createtextnode(doc, 'false');
    arg2_node := xmldom.appendchild(arg2_node, xmldom.makenode(arg2_text));
    request := xmldom.getxmltype(doc);
    pl('Request:');
    pl(request.getStringVal());
    response := sys.utl_dbws.invoke(call_, request);
    pl('Showing respons');
    pl(response.getStringVal());
    doc := DBMS_XMLDOM.newDomDocument(response);
    sys.utl_dbws.release_call(call_);
    sys.utl_dbws.release_service(svc_);
    end forwardToQueue;

    Is the Document well defined via schema? You might be able to use the autotype
    ant task to generate a serializer.
    Otherwise, serialize the document to a string, then wrap it in <[CDATA[...]]>
    on the return. The calling app will need to understand that the string is xml,
    and then desrailize it manually.
    Mike
    "Surya" <[email protected]> wrote:
    >
    I have web service which has to retuen an XML document (org.w3c.dom.Document)
    as
    a paramter. Since this is not a supported data type for in-out paramaters,
    I will
    have to serialize and write my own converter. What is the best solution?
    Is there
    any class/library that can convert the document into String which I can
    return
    as a parameter and again get create a XML document in the client side.
    Thanks -Surya

  • Error while generating an XML Document from XML Schema with JAXB

    Hi,
    I am following this OTN tutorial to generate the XML document from Java classes got from the XSD document.
    http://www.oracle.com/technology/pub/notes/technote_jaxb.html
    I am able to generate all the Java classes but getting error on compiling the XMLConstructor.java class which is use for generating the XML document :
    I am using JDK 1.5 and
    Oracle 10g XML Developer's Kit (XDK) Production for Java. xdk_nt_10_1_0_2_0_production
    (though these are warnings I am not able to run it.)
    Error
    C:\Prototype\classes\jaxbderived\catalog>javac -Xlint XMLConstructor.java
    warning: [path] bad path element "%CLASSPATH%": no such file or directory
    XMLConstructor.java:42: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
    journalList.add(journal);
    ^
    XMLConstructor.java:46: warning: [unchecked] unchecked call to add(E) as a membe
    r of the raw type java.util.List
    articleList.add(article);
    Thanks
    Sanjeev ([email protected])

    Use JDK 1.4.

  • XML document could not be created because server memory is low( SCOM 2012 R2).

    Hi 
    I am facing below issue in the scom 2012 r2.
    please find the error below 
    On SCOM MS:
    Alert name :Data Warehouse relationship synchronization process failed to write data 
    Alert description :Data Warehouse relationship synchronization process failed to write data to the Data Warehouse database. Failed to store data
    in the Data Warehouse. The operation will be retried.
    Exception 'SqlException': Sql execution failed. Error 6624, Level 16, State 1, Procedure sp_xml_preparedocument, Line 1, Message: XML document could not be created because server memory is low. Use sp_xml_removedocument to release XML documents.
    Event id in Operation log:  
    Event id :33333 
    Data Access Layer rejected retry on SqlError:
     Request: DataWarehouseSynchConfigChangeTypeGet -- (InstalledManagementPackXml=<ManagementPacks><ManagementPack>7b9f4239-7351-e72b-4ce4-d6c56ddb401d</ManagementPack><ManagementPack>848edb97-9da5-e2ae-24d4-56...),
    (RETURN_VALUE=-6)
     Class: 16
     Number: 6624
     Message: XML document could not be created because server memory is low. Use sp_xml_removedocument
    to release XML documents.
    ON SCOM DB server:
    SQL version : SQL 2012 SP1 X64 bit Host all SCOm db (SCOM DB,SCOM DW,Reporting)
    Ervent id : 28005 ,Application log,source: MSSQLSERVER
    Please suggest me in this regard.
    Thanks 
    sridhar v

    For fix error 33333, you can refer below links
    http://opsmgradmin.blogspot.com/2011/05/scom-event-id-33333-in-scom-from-source.html
    http://systemcenterblog.blogspot.com/2009/11/error-id-33333-data-access-layer.html
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer"
    Mai Ali | My blog: Technical | Twitter:
    Mai Ali

  • XML document from parser

    Generally , parsers are used to parse XML document.
    Is it possible to create XML document/file from a parser

    A parser such as javax.xml.parsers.DocumentBuilderis used to parse an XML document with the parsemethods. Theparsemethod returns a org.w3c.dom.Documentfrom which elements/attributes may be obtained with the get methods. A document may be created with the newDocument() method of the DocumentBuilder class.
    The elements/attributes are created with createElement and createAttribute methods in the Document interface.
    http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder.html
    http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Document.html

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

  • Xml Document is not formed correctly.. Help me..

    Using the .xsd files provided to me, I created XMLBeans using the schema project in weblogic 8.1 sp2.
    These XMLBeans are used to create a XML document in my Weblogic Integration process. The values in the xml document are retrieved from a database (which cannot administered/viewed by me). XML document was formed perfectly. But recently when I tried running the application again, I found that the xml is not created properly.
    When I tried to print the xml message, it displays the xml message with the first letter changed from '<' to '<'.
    eg.
    <batch_document>
    </batch_document> is displayed as
    <batch_document>
    </batch_document>
    What may be the reason behind this change. Is it possible because of some invalid data from the backend? If so, what could be the data?
    Is there any special characters which when inserted between the elements makes the document like this?
    The code that creates the xml document looks like this ...
    BatchDocumentDocument bDoc= BatchDocumentDocument.Factory.newInstance();
    BatchDocument bd= bDoc.addNewBatchDocument();
    System.out.println(bDoc.toString());
    The print statement prints the xml message as
    <batch_document>
    </batch_document>
    I would be grateful even if I am answered with any of these questions.
    Thanks in advance.

    Hello Elango,
    Have you tried validating the instance document using the validate() method
    -Raj
    <Elango SV> wrote in message news:[email protected]..
    Using the .xsd files provided to me, I created XMLBeans using the schema
    project in weblogic 8.1 sp2.
    These XMLBeans are used to create a XML document in my Weblogic
    Integration process. The values in the xml document are retrieved from a
    database (which cannot administered/viewed by me). XML document was formed
    perfectly. But recently when I tried running the application again, I
    found that the xml is not created properly.
    When I tried to print the xml message, it displays the xml message with
    the first letter changed from '<' to '<'.
    eg.
    <batch_document>
    </batch_document> is displayed as
    <batch_document>
    </batch_document>
    What may be the reason behind this change. Is it possible because of some
    invalid data from the backend? If so, what could be the data?
    Is there any special characters which when inserted between the elements
    makes the document like this?
    The code that creates the xml document looks like this ...
    BatchDocumentDocument bDoc= BatchDocumentDocument.Factory.newInstance();
    BatchDocument bd= bDoc.addNewBatchDocument();
    System.out.println(bDoc.toString());
    The print statement prints the xml message as
    <batch_document>
    </batch_document>
    I would be grateful even if I am answered with any of these questions.
    Thanks in advance.

Maybe you are looking for

  • Data recovery question

    Hi, I'll try to make this as clear as possible. A little while ago my powerbook suffered a fall on pavement. Not only did the hinges break but the battery adapter input module on the inside of the case broke as well. Now the internal battery can't ta

  • How can we call a report from a form.

    how can we call a report from an existing form.

  • Photoshop CS5 Crash - Possible cause - magnetic lasso tool

    Hi, One of our artist machines has been crashing regularly and it tends to happen when the magnetic lasso tool is being utilized.  I've done some research on existing CS5 crashes related to the magnetic tool and in most cases was due to the size of t

  • Help with Lo Cockpit

    Hi, Could anyone please provide me the detailed steps for Lo Cockpit Extraction on both ECC side and BW side. Thanks, Neha

  • Lost some of my photos after upgrading, though I can still see the previews.

    My 2.66 intel core i5 IMAC recently had a HD crash.  Fortuneatly I had a 2T western external HD set up as a time machine.  The local Apple reseller checked the HD and had it replaced.  When I got my PC back I noticed it had the newer operating system