Serializing XML Documents(not Java Serialization)

Hi,
Iam looking for a class that can serialize the XML documents.
Heres the problem in detail:
- I need to create an XML String from scratch taking data from a database.
- I created the XML Document adding the childs and attributes.
- I need an XML string from the document. Iam not exactly sure how to do this. But Apache Xerces package provides an XMLSerializer class where we can convert the document into a string.
Is there any functionality provided. If so where can i find it.
Thanks,
-Rao

Not sure if this is a bug or not (filing one just in case it is) but the following program demonstrates that with 2.0.2.9 the internal subset is serialized correctly if the document was parsed with validationMode set to true. If set to false only the entities show up in the internal subset.
package xmlbugs;
import java.io.*;
import org.w3c.dom.*;
import oracle.xml.parser.v2.*;
public class TestSerializeLocalSubset {
private static final String xml =
"<?xml version='1.0' encoding='UTF-8'?>"+
"<!DOCTYPE bar ["+
"<!ENTITY bar 'baz'>"+
"<!ELEMENT foo EMPTY >"+
"<!ELEMENT bar (foo) >"+
"]>"+
"<bar><foo/></bar>";
public static void main(String[] a_ ) throws Exception {
System.out.println("Test with parser in validation mode = false");
DOMParser d = new DOMParser();
d.setPreserveWhitespace(false);
d.setValidationMode(false);
d.parse( new StringReader(xml));
Document x = d.getDocument();
XMLDocument xx = (XMLDocument) x;
xx.print(System.out);
System.out.println("Test with parser in validation mode = true");
DOMParser d2 = new DOMParser();
d2.setPreserveWhitespace(false);
d2.setValidationMode(true);
d2.parse( new StringReader(xml));
x = d2.getDocument();
xx = (XMLDocument) x;
xx.print(System.out);
}

Similar Messages

  • Error serializing XML document.

    We are trying to serialize XML document using Oracle XML Parser (9.2.0.5.0).
    Here is the code used for serialization
    public static void write(Document doc, File resultFile) {
    try {
    // Create a TransformerFactory
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    // Create a new Transformer for Identity Transformation
    Transformer transformer = transformerFactory.newTransformer();
    // Make passed document the DOM source
    DOMSource source = new DOMSource(doc);
    // Make result file the Stream Result
    StreamResult result = new StreamResult(new FileOutputStream(resultFile));
    // Write the document by means of Identity Transformation
    transformer.transform(source, result);
    } catch (Exception exc) {
    exc.printStackTrace();
    Document to be serialized
    test.xml
    <?xml version="1.0"?>
    <!DOCTYPE test SYSTEM "test.dtd">
    <!-- This is a comment -->
    <Test>
    <TestElement>Test Data</TestElement>
    </Test>
    test.dtd
    <!-- DTD -->
    <!ELEMENT Test (TestElement)>
    <!ELEMENT TestElement (#PCDATA)>
    The serialized document looked like
    <?xml version = '1.0'?>
    <?#comment This is a comment ?><Test>
    <TestElement>Test Data</TestElement>
    </Test>
    First of all the DOCTYPE declaration was not present in the serialized document.
    Secondly the comments appeared in a wrong way, which even made it an invalid XML document.
    How do we get this to work?
    Thanks
    Sagar

    On 9.2.0.3.0 you can try dbms_xdb.deleteResource(Path,4)

  • Reading UTF-7 XML document in Java

    I have an XML document and I want to add PrcessingInstruction to it.
    <?xml version="1.0" encoding="UTF-7" ?>
    <root_element>
    <sections>
    <section_introduction>
    <order-no>108800674</order-no>
    <order-type>219</order-type>
    <created-date>5. november 2008</created-date>
    when trying to parse it like
    File tmpFile = new File("C:\\ProvisioningEventError58412.xml");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    Document doc = factory.newDocumentBuilder().parse(tmpFile);
    System.out.println("end");
    I get an exception on Document doc = factory.newDocumentBuilder().parse(tmpFile);
    org.xml.sax.SAXParseException: Invalid encoding name "UTF-7".
    [Fatal Error] ProvisioningEventError58412.xml:1:40: Invalid encoding name "UTF-7".
    Is it possible to set encoding on DocumentBuilder, so it can work with UTF-7 or is there any other was to parse it for adding ProcessingInstruction. Actually I want to add a CSS/XSL file for formatting the XML File.
    Edited by: aamaam on Jul 15, 2009 5:18 AM

    As you will see from [this Supported Encodings document|http://java.sun.com/javase/6/docs/technotes/guides/intl/encoding.doc.html], it's Java which doesn't support UTF-7, not just DocumentBuilder.
    So you have a couple of options. You could send the document back to whoever produced it and tell them that you can't process it the way it is. That's a legitimate thing to do because [the XML Recommendation|http://www.w3.org/TR/REC-xml/] only requires parsers to support UTF-8 and UTF-16. Support for other encodings is optional.
    Or you could write your own subclass of InputStreamReader which converts a stream of UTF-7 bytes into a stream of chars, and use that as a Reader which you pass to the parser. Somebody may even have done that already and posted it on the web somewhere.

  • XML Document not Valid

    Hi Techies,
    I m making a xml document and that is validated on xml schema. But it is giving error that document is not valid because it is not deg\fining DOCTYPE element. Is it necessary to define it

    It is not nesessary, but you have probably made your parser validating. In Java validating parsers use DTD to validate, and while schema validation is possibly those parsers are non-validating.

  • How to append child to XML document using Java

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
         <bean name="PinnacleReportsData"
              class="com.hsbc.webapp.report.view.GenericPinnacleReportsViewData"
              singleton="false">
              <property name="headers">
                   <value>Account|Cusip|Description|SecType|Sector|Holding|Price|MarketValue|SettleDate|Yield|SprdUST|AL|CFDur|OAS|ZVolOas|OADur|PrepayDur|VolDur|DV01|DVOAS01|KRDur10Y|PrepayModelCalled|CalcError|CalculationTime</value>
              </property>     
              <property name="noOfRows">
                   <value>20</value>
              </property>     
              <property name="rowdata">
                   <list>
                        <value>AA09b|CMO|8000|8000|62052MAD0|MFPLC_4A 2A 144A||8097|99-27+|5.18|0.25|200|0.00||15||||</value>
                        <value>AA09b|CMO|10000|10000|320277AD8|HASCO 2005 F II-A-2||9958|99-13|5.69|0.13|131|0.02||154|0.000|25|0.001|9864</value>
                        <value>AA09b|CMO|8000|2363|46071LAA8|IMT_03-3G A2||2378|100-01|5.18|0.14|33|0.00||2||||</value>
                        <value>AA09b|CMO|1270|312|40430HDW5|HASCO 2006-O II-A-1||309|99-00|8.98|0.16|5|0.01||3|0.000|1|0.001|296</value>
                        <value>AA09b|CMO|5000|5000|40430HFQ6|HASCO 2006-O M-3||4583|91-15+|8.99|1.16|534|-0.58|-2|-2644|0.016|712|0.080|367625</value>
                        <value>AA74b|ABS|8000|8000|62052MAD0|MFPLC_4A 2A 144A||8097|99-27+|5.18|0.25|200|0.00||15||||</value>
                        <value>AA74b|ABS|10000|10000|320277AD8|HASCO 2005 F II-A-2||9958|99-13|5.69|0.13|131|0.02||154|0.000|25|0.001|9864</value>
                        <value>AA74b|ABS|8000|2363|46071LAA8|IMT_03-3G A2||2378|100-01|5.18|0.14|33|0.00||2||||</value>
                        <value>AA74b|ABS|1270|312|40430HDW5|HASCO 2006-O II-A-1||309|99-00|8.98|0.16|5|0.01||3|0.000|1|0.001|296</value>
                        <value>AA74b|ABS|5000|5000|40430HFQ6|HASCO 2006-O M-3||4583|91-15+|8.99|1.16|534|-0.58|-2|-2644|0.016|712|0.080|367625</value>
                   </list>
              </property>
         </bean>
    </beans>               hi there i have a XML Document above,and i need to append values to the <list> using java.
    i have string values like
         <value>AA74b|ABS|5000|5000|40430HFQ6|HASCO 2006-O M-3||4583|91-15+|8.99|1.16|534|-0.58|-2|-2644|0.016|712|0.080|367625</value>to add, but failing to navigate to the <list>
    any help?

    1. Read the XML file into a DMO object, walk the DOM to find the list, insert your new entry as a child, write the DOM back to a file.
    2. If the XML is not in a file, but in a string, then you can do the same with string input and output.

  • Validating xml document in java

    Trying to do subject.
    I'm trying to use xsd from file(schemasource = 1) and from clob (schemasource = 0). I have two xsd schemas common_types.xsd and migom.xsd. second includes first. The problem is that when I'm using common_types schema from file I get error
    ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.parser.v2.XMLParseException: An internal error condition occurred.
    and when I validate xml against only first schema has being read from clob I get success, but when I add second xsd, i get the same error, which says nothing at all.
    create or replace and compile java source named XmlTools AS
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.XMLReader;
    import org.xml.sax.InputSource;
    import oracle.sql.CLOB;
    import java.io.IOException;
    import org.xml.sax.SAXException;
    import java.sql.SQLException;
    import java.lang.IllegalArgumentException;
    import oracle.xml.parser.v2.XMLParseException;
    import javax.xml.parsers.ParserConfigurationException;
    import java.io.*;
    public class XmlValidator
    static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
    static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    public static void ValidateDocument(int schemasource, oracle.sql.CLOB schemadoc, oracle.sql.CLOB schemadoc1, oracle.sql.CLOB xmldoc) throws SAXException, IOException, SQLException, ParserConfigurationException, XMLParseException, IllegalArgumentException {
    try
    File myfile = new File(".//XML//common_types.xsd");
    if (myfile.exists())
    Serv.log("ValidateDocument", "file size" + Long.toString(myfile.length()));
    /*else
    Serv.log("ValidateDocument", "file doesn't exists" );
    Serv.log("ValidateDocument", "1" );
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    Serv.log("ValidateDocument", "2" );
    SAXParser saxParser = factory.newSAXParser();
    saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    if (schemasource == 0)
    InputSource schemaIs = new InputSource(schemadoc.getCharacterStream());
    InputSource schemaIs1 = new InputSource(schemadoc1.getCharacterStream());
    InputSource[] schemas = {schemaIs, schemaIs1};
    //saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaIs);
    saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemas);
    else
    saxParser.setProperty(JAXP_SCHEMA_SOURCE, ".//XML//common_types.xsd");
    XMLReader reader = saxParser.getXMLReader();
    //Получаем входной XML документ
    InputSource documentIs = new InputSource(xmldoc.getCharacterStream());
    Serv.log("ValidateDocument", "3" );
    //Запуск разбора
    reader.parse(documentIs);
    Serv.log("ValidateDocument", "4" );
    documentIs = null;
    /*catch (SAXException e)
    Serv.log("ValidateDocument", "SAXException" );
    Serv.log("ValidateDocument", "document is not valid because ");
    Serv.log("ValidateDocument", e.getMessage());
    throw(e);
    catch (ParserConfigurationException e)
    Serv.log("ValidateDocument", "ParserConfigurationException" );
    throw(e);
    catch (IOException e)
    Serv.log("ValidateDocument", "IOException" );
    throw(e);
    catch (XMLParseException e)
    Serv.log("ValidateDocument", "XMLParseException" );
    Serv.log("ValidateDocument", e.getMessage());
    StackTraceElement[] stack = e.getStackTrace();
    for (int i = 0; i < stack.length; i++)
    Serv.log("stacktrace element no " + Integer.toString(i), "toString: " + stack.toString());
    Serv.log("stacktrace element no " + Integer.toString(i), "file name: " + stack[i].getFileName() + ", class name: " + stack[i].getClassName() + ", method name: " + stack[i].getMethodName() + ", line : " + stack[i].getLineNumber());
    throw(e);
    catch (IllegalArgumentException e)
    Serv.log("ValidateDocument", "IllegalArgumentException" );
    Serv.log("ValidateDocument", e.getMessage());
    throw(e);
    additional information got from java stacktrace:
    file name: XMLError.java, class name: oracle.xml.parser.v2.XMLError, method name: flushErrors1, line : 320 file name: NonValidatingParser.java, class name: oracle.xml.parser.v2.NonValidatingParser, method name: parseDocument, line : 300 file name: XMLParser.java, class name: oracle.xml.parser.v2.XMLParser, method name: parse, line : 200 file name: XMLTOOLS, class name: XmlValidator, method name: ValidateDocument, line : 86
    my oracle version is Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod But my aim is to make it work on all versions starting from 9

    I found another examples of xml document validation in Java, but it seems to me that ORACLE's JVM doesn't include such class as SchemaFactory and class SAXParserFactory doesn't have method setSchema. Is it possible to update JVM installed in Oracle?
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);
    SchemaFactory schemaFactory =
    SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    factory.setSchema(schemaFactory.newSchema(
    new Source[] {new StreamSource("contacts.xsd")}));
    SAXParser parser = factory.newSAXParser();
    XMLReader reader = parser.getXMLReader();
    reader.setErrorHandler(new SimpleErrorHandler());
    reader.parse(new InputSource("document.xml"));

  • Generic Populating the XML document using Java Class Generator and Reflection

    I am looking for a generic source code in order to convert the data parsed from any tabular text form ( tab delimited for example that maps certain XML Schema created form Database Schema for Oracle.
    I know it is possible to generate XML DTD or XSD from Oracle database table schema by XSU utility from XDK. And also it is possible to create Java source files from an XML DTD or XSD by using XML Clas Generator.
    I believe there must be some generic code that parses tabular text data and converts them to XML format using above mentioned generated Java source files and may be Java reflection mechanism.
    If anyone has any tool or knows any free ware that helps me, I would like to know about it, and I would really appreciate it.

    1. Read the XML file into a DMO object, walk the DOM to find the list, insert your new entry as a child, write the DOM back to a file.
    2. If the XML is not in a file, but in a string, then you can do the same with string input and output.

  • How to create XML document in Java from scratch ?

    I've downloaded the package generated for my schema.
    Now I'm trying to create a XML Document using the interfaces generated and the
    xmlbeans package. In documentation, all samples start with a call to XmlLoader.load(xmlinput).
    In my case I've no xmlinput, I've only java parameters and i need to produce an
    XML document.
    Could you provide a sample code please ?
    Thanks in advance.

    It looks like you only need to use the xmlText() method from the root of any node
    you want to print out to a file. I used a PrintStream() class and then used the
    ps.print(vpDetails.xmlText()); to save to a file.
    Hope this helps.
    Jerald
    "Eric Vasilik" <[email protected]> wrote:
    >
    To create a new, untyped document:
    XmlObject x = XmlLoader.newInstance();
    To create a new, typed document:
    Map options = new HashMap(
    XmlOptions.DOCUMENT_TYPE,
    CustomerDocument.type );
    CustomerDocument cd = (CustomerDocument) =
    XmlLoader.newInstance( options );
    I have changes pending which will alow you to do this more easily:
    CustomerDocument cd = CustomerDocument.Factory.newInstance();
    - Eric
    "Pascal Fuget" <[email protected]> wrote:
    I've downloaded the package generated for my schema.
    Now I'm trying to create a XML Document using the interfaces generated
    and the
    xmlbeans package. In documentation, all samples start with a call to
    XmlLoader.load(xmlinput).
    In my case I've no xmlinput, I've only java parameters and i need to
    produce an
    XML document.
    Could you provide a sample code please ?
    Thanks in advance.

  • Writing to an xml document, not working.

    Hey all,
    I'm trying to do something pretty simple, just setting up a phone forwarding script (I believe it is the one that came with CCX) that reads XML documents to forward and unforward the phones.  But I cant for the life of me get the script to actually write to a status file on ccx.  Please take a look at my script and help me out.

    Figured it out.  You have to write to a different directory.

  • Serializing XML documents throws AIOOBE

    I have a bunch of XMLDocuments that are generated from Forms modules with the Forms2XML.dumpModule but when I try to serialize the collection through and ObjectOutputStream, I end up with a
    java.lang.ArrayIndexOutOfBoundsException: 16388
         at oracle.xml.comp.CXMLStream.writeUTF(CXMLStream.java:638)
         at oracle.xml.parser.v2.XMLAttr.writeExternal(XMLAttr.java:834)
         at oracle.xml.parser.v2.XMLElement.writeExternal(XMLElement.java:2333)
         at oracle.xml.parser.v2.XMLElement.writeExternal(XMLElement.java:2355)
         at oracle.xml.parser.v2.XMLElement.writeExternal(XMLElement.java:2355)
         at oracle.xml.parser.v2.XMLDocument.writeExternal(XMLDocument.java:2746)
         at oracle.xml.parser.v2.XMLDocument.writeExternal(XMLDocument.java:2678)
    My guess is that some stuff nested in XMLDocument implement the java.io.Externalizable interface and tries to do stuff itself and fails.
    When I look at the generated XML, it shows that the encoding is "UTF-8" but there are unencoded ISO-8859-1 chars in the doc so it could be what the writeUTF is complaing about? Is there some way of mangling the document to the correct encoding or other applicable magic?

    Hello,
    Did you managed to solve this problem ? I'm getting the same error if i try to load an xml in a queue using oracle OJMS.
    Replacing the xmlparserv2.jar by the one from oc4j v 10.1.3 solved the problem, but this is not supported in a production environmen.
    grtz,
    Chris.

  • Getting Node Value of an XML document in JAVA.

    Hi,
    In my application, I have got the exact node that I want by parsing the document, but the node value returned is null as the node is an element and the Java Documentation does specify that it will return null. I would like to know if there in any alternative way by which I can parse the document and get the specified value of the node or element. Kindly Help.

    Well, there are not many mind readers on this forum.
    You do not tell us how you are parsing the document, and so it is difficult determining why the node value is returned as a null.
    There are two main styles of processing XML -- DOM and SAX. Dom (and its variants JDom and I think Dom4J) build a tree structure that is memory-resident. There are ways to walk up and down the tree, and locate arbitrary nodes in the tree.
    The other style is SAX, which is much less intensive from a memroy perspective, but puts more work on you to keep what you want as the data goes flying by.
    So, how are you "parsing the document" and what method is returning a null? That may give someone enough information to guess at your problem.
    Dave Patterson

  • XML Document Not working / Capture device problems HELP!

    Whenever i open the xml file from justin.tv it always says "Log File Cannot Be Created," then ist says "Profile Vlidation"
    And whenever i select my captutre card it always says " Problem With Video Capture Device"
    Somone please help me!
    (i have attached the xml file that keeps on crashing for me)

    You are getting "Log File Cannot Be Created" error because when you download XML file from someone else computer then FMLE  by default folder takes path for Log file as his "My Videos" folder. So while checking the profil, FMLE gets to know that this profile is not perfect and hence gives "Profile Validation Error" and then silently corercts those errors. After clicking OK on "Profile Validation error" window, you can go to Encoding log tab and check the changes that were made in FMLE on above the settings of your XML profile file.
    You are getting "Problem With Video Capture Device" because either the drivers of your device are not corerctly isntalled on your machine or your device is busy with some other application or your device is not connected properly. Please check the drivers and connectivity of your device and make sure that your device gives RAW/Uncompressed Video format only

  • Default to Java Serialization in case Pof Serialization not defined

    Is this possible to do, i.e. essentially if for a certain class Pof serialization is not defined, use the Java serialization instead?
    Or to turn it around, is it possible to define pof serialization only for certain classes in a distributed cache and use Java serialization for the rest?

    Hi,
    the problem for this is that Java serialization is not aware of POF (or for that matter even ExternalizableLite), so if you have a Java-serialized class which has a member which is supposed to be POF-serializable, it in fact will not be serialized with POF, because Java serialization will not delegate to POF.
    So it is very hard to mix the two together. You can do it for top-level objects by providing a special PofSerializer instance for the non-POF class which serializes to byte array and you write the byte array as a POF attribute, but it is not possible for POF-aware objects contained within a non-POF aware object to be POF serialized.
    Also, if you attempt to do this, then you can kiss goodbye to platform independence. You must use Java on both ends and have all the libraries which the classes used in the state want to pull in.
    Best regards,
    Robert

  • XML document reading in java

    Hello
    Can any one help me to read XML document in JAVA
    Thank u

    I'd use the nanoXML parser because it's small enough to fit easily on a STB.
    Roger

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

Maybe you are looking for

  • Calendar in mobile browser not showing month view

    I have a Calendar. I looked under Modify This View, and got the web address for this mobile view. When I bring up this url in a browser on an ipad/iphone, the calendar doesn't display in Month view. It only shows one day. very strange view. and only

  • Error While Uploading the Vendors Data

    Hi Friends, iam uploading the vendors information. In the XL-Sheet there are 5 Records are there.the first two records are correct.but iam getting the following message for the frist two records.iam using the call transaction method. No memory is ava

  • Display problem in iOS7

    The "Adobe & Higher Education" app (produced by Adobe in August 2012) is not displaying correctly in iOS7. It appears to either be frozen in vertical mode yet it was designed just for horizontal, or the articles appear as blank gray. I did not have t

  • Toggling between foreign language keyboards possible?

    Hi! I am learning Hebrew and would like to make flash cards on my Mac, which means I'll be typing in both English and Hebrew. I've already successfully set up the Hebrew and English keyboards via the International Preference Pane. My question is: *Ca

  • Horrible slow down, only when downloading files??

    Hi I am getting terrible slowdown and the dreaded spinning wheel on my iMac, but only when I am downloading files using a web browser. I have tried Safari, Opera, and firefox and the problem still remains. It only seems to happen when Im downloading