DOM parsing from memory avoid deprecated class usage

I am parsing an xml file from memory stored in a StringBuffer xmlBuffer like this
try {
               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
               DocumentBuilder db = dbf.newDocumentBuilder();
               InputStream is = new StringBufferInputStream(xmlBuffer.toString());
               Document doc = db.parse(is);How can i avoid using of that deprecated class?

Why are you storing the file in memory in a StringBuffer? You could use this method directly:
[http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html#parse(java.io.File)]
or from a URI:
[http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html#parse(java.lang.String)]
StringBufferInputStream is deprecated because it does not properly convert characters into bytes.

Similar Messages

  • Getting DOM Parsing Exception in translator while Dequeuing the message from JMS topic

    Hi All,
    Hope you all doing good.
    I have an issue.
    I am running on 11.1.1.5 SOA suite version on Linux.
    In my aplication I have 4 projects which are connected by with topic/queue.
    But in one of the communication, the JMS topic throws me the below error in the log, but dequeue happend perfectly fine and the application runs smoothly.
    [ERROR] [] [oracle.soa.adapter] [tid: weblogic.work.j2ee.J2EEWorkManager$WorkWithListener@530c530c] [userId: <anonymous>
    ] [ecid: 5552564bd7cf9140:-117a2347:142149c715a:-8000-00000000069dd133,0] [APP: soa-infra] JMSAdapter <project1>
    JmsConsumer_sendInboundMessage:[des
    tination = <TOPIC NAME>  subscriber = <Consumer project name>
    Error (DOM Parsing Exception in translator.[[
    DOM parsing exception in inbound XSD translator while parsing InputStream.
    Please make sure that the xml data is valid.
    ) while preparing to send XMLRecord JmsXMLRecord
    [ERROR] [] [oracle.soa.adapter] [tid: weblogic.work.j2ee.J2EEWorkManager$WorkWithListener@530c530c] [userId: <anonymous>
    ] [ecid: 5552564bd7cf9140:-117a2347:142149c715a:-8000-00000000069dd133,0] [APP: soa-infra] JMSAdapter <project name>
    java.lang.Exception: DOM Parsing Exception in translator.
    DOM parsing exception in inbound XSD translator while parsing InputStream.
    Please make sure that the xml data is valid.
            at oracle.tip.adapter.jms.inbound.JmsConsumer.translateFromNative(JmsConsumer.java:603)
            at oracle.tip.adapter.jms.inbound.JmsConsumer.sendInboundMessage(JmsConsumer.java:403)
            at oracle.tip.adapter.jms.inbound.JmsConsumer.send(JmsConsumer.java:1161)
            at oracle.tip.adapter.jms.inbound.JmsConsumer.run(JmsConsumer.java:1048)
            at oracle.integration.platform.blocks.executor.WorkManagerExecutor$1.run(WorkManagerExecutor.java:120)
            at weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:184)
            at weblogic.work.DaemonWorkThread.run(DaemonWorkThread.java:30)
    But when I try putting the archived data on this topic, it throws me the same error but even dequeuing doesnt happen.
    I have extracted the payload and validated against the xsd, it looks fine and even the validator doesnt throw me any error.
    But I guess I am missing something, which I am immediately not getting.
    Please let me know, if I am soemthing here which is causing this erro.
    Thanks,
    Chandru

    I searched about this error, but no luck.
    First time when the message dequeues, the consumer can consume the message but throws the error in the log.
    But when I put the message back into queue from archive directory, the consumer doesnt consume message and throws me the same error.
    Does anyone faced this sort of issue.
    I checked my xsd throughly, and validated it externally. but didnt fine any error.
    if anyone knows, suggest me how to resolve this issue.
    thanks & regards
    Chandru

  • Generating XMLs from CSVs using DOM parser......

    Hi,
    I am trying to generate XMLs from CSV files using DOM parser. XMLs are getting generated but the problem is that i am using Encoding "ISO-8859-1" but XMLs are getting generated in UTF-8 encoding.
    Please refer to the code below and advice. (where are the code tags gone ????? )
    Source domSource = new DOMSource(document);
    ByteArrayOutputStream xmlStream = new ByteArrayOutputStream();
    Result result = new StreamResult(xmlStream);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.transform(domSource, result);
    xmlStream.close();
    generatedXml = new String(xmlStream.toByteArray(), "*ISO-8859-1*");

    Use transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1") to specify the character set.

  • Error message: Error parsing properties list from memory

    When I try to open my website that I built with Adobe Muse CC in Adobe Muse CC 2014 comes the error message: "error parsing properties list from memory" an everything is stuck, I can't open anything or working not even the preview mod is working, nothing. The same problem/message comes up when I try to star a new site. So I just can't work with the new Adobe Muse CC 2014 (I updated today the new launch). Does anyone know what is going on here? Is it a bug or what?

    This just happened to me. I've had no trouble at all with the latest version of abobe muse until today...Its still working alittle..I can't access sites but not via thumbnail have to click tab. My major issue is the side toolbar not loading.
    Any fix known??

  • ✓ not output correctly from DOM parser

    Need a small help again.
    in my original XMl file, I have an entity &#671;
    It represents(ALT 671) a check symbol(a box).
    But the output XMl file from my DOMparser represents it as a question mark, which is NOT what I want.
    I'm using DOM parser with JAXP API to parse the XML file.
    Could you help me why does my parser doesn't output correct character for this particular entity only?
    Any suggestion is grately appreciated.
    -Srivalli.

    Thanks DrClap for your reply.
    Here is the statement in my DTD...
    <!ENTITY check     "&#10003;">
    (I had 671 in the place of 10003, but neither worked!!!!)
    This is a statement in input XML...
    The foll &check; owing is
    This is my Output XML....
    The foll ? owing is
    Here is the code in my java file where I didnot explicitly specify any output encoding type....
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setIgnoringElementContentWhitespace(true);
    DocumentBuilder builder=factory.newDocumentBuilder();
    currDocument=builder.parse(f);
    TransformerFactory tf=TransformerFactory.newInstance();
    Transformer t = tf.newTransformer(new StreamSource("transformoutput.xsl"));
    t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "nmstat.dtd");
    FileWriter fileOut = new FileWriter("outputAnno.xml");
    t.transform(new DOMSource(document), new StreamResult(fileOut));
    This is the code in transformoutput.xsl...
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
    <xsl:copy-of select="node()"/>
    </xsl:template>
    </xsl:stylesheet>
    Could you help me figuring out the problem.
    Thank you very much.
    -Srivalli.

  • How to read xml-stylesheet Processing Instruction from XML using DOM Parser

    Hi,
    I am trying to read an xml that contains xsl stylesheet PI using DOMParser. The parse() method reads the entire contents of the XML except the PI instruction. Below is the XML I am using to read
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet href="../../../lang/en-us/style0/usc_profile.xsl" type="text/xsl"?>
    <Oblix oblang="en-us" xmlns="http://www.oblix.com/" xmlns:oblix="http://www.oblix.com/">
    <ObProfile>
    </ObProfile>
    </Oblix>
    Can anyone let me know if there are any propery settings to be done for the DOM parser before parsing?. If so, what is the property to be set?.
    Thanks in Advance
    Muthu

    A COTS product builds the XML and inserts the respective xsl (xml:stylesheet) file name to be used for transforming the xml. I am trying to interrupt this xml and make some updations on an element and finally send the updated xml to the stream.
    For the above process, I parse the input XML using DOMParser and update the elements (some internal elements). While I view the final XML that would be passed to the stream, I found the <?xml-stylesheet... PI is missing.
    I somehow managed using a temp fix by doing the below. I manually pulled the PI using document.getFirstChild().getNodeValue() and reconstructed the PI and inserted it to the outgoing XML. This needs to be done every time. This might run into problems when more than one PI is used in the XML.
    If the parsed XML could get the PI along with it the above problem could be resolved.
    Is there any property that could be set on the parser (prior to parsing) to resolve the issue?.

  • Oracle XML DOM parser - attribute values are not printing on the screen ??

    Hi Everyone,
    I am just trying to use oracle DOM parser to paerse one of my xml file, java file can be compiled and run agianst a xml file, But I cannot see any attribute values printing on the screen..
    Appreciate if anyone can help, where I have gone wrong please?
    Below is the java file:
    // menna puthe DOMSample eka - duwanawa 19/12/2005
    import java.io.*;
    import java.net.*;
    import org.w3c.dom.*;
    import org.w3c.dom.Node;
    import oracle.xml.parser.v2.*;
    public class DOMSample {  //public class eka ***
    static public void main(String[] argv){  // main method eka ###
    try {
    if (argv.length != 1){
    // Must pass in the name of the XML file...
    System.err.println("Usage: java DOMSample filename");
    System.exit(1);
    // Get an instance of the parser
    DOMParser parser = new DOMParser();
    // Generate a URL from the filename.
    URL url = createURL(argv[0]);
    // Set various parser options: validation on,
    // warnings shown, error stream set to stderr.
    parser.setErrorStream(System.err);
    parser.showWarnings(true);
    // Parse the document.
    parser.parse(url);
    // Obtain the document.
    Document doc = parser.getDocument();
    // Print document elements
    System.out.print("The elements are: ");
    printElements(doc);
    // Print document element attributes
    System.out.println("The attributes of each element are: ");
    printElementAttributes(doc);
    catch (Exception e){
    System.out.println(e.toString());
    } // main method eka ###
    static void printElements(Document doc) {
    NodeList nl = doc.getElementsByTagName("*");
    Node n;
    for (int i=0; i<nl.getLength(); i++){
    n = nl.item(i);
    System.out.print(n.getNodeName() + " ");
    System.out.println();
    static void printElementAttributes(Document doc){
    NodeList nl = doc.getElementsByTagName("*");
    Element e;
    Node n;
    NamedNodeMap nnm;
    String attrname;
    String attrval;
    int i, len;
    len = nl.getLength();
    for (int j=0; j < len; j++){
    e = (Element)nl.item(j);
    System.out.println(e.getTagName() + ":");
    nnm = e.getAttributes();
    if (nnm != null){
    for (i=0; i<nnm.getLength(); i++){
    n = nnm.item(i);
    attrname = n.getNodeName();
    attrval = n.getNodeValue();
    System.out.print(" " + attrname + " = " + attrval);
    System.out.println();
    static URL createURL(String filename) {  // podi 3 Start
    URL url = null;
    try {
    url = new URL(filename);
    } catch (MalformedURLException ex) { /// BBBBBB
    try {
    File f = new File(filename);
    url = f.toURL();
    } catch (MalformedURLException e) {
    System.out.println("Cannot create URL for: " + filename);
    System.exit(0);
    } // BBBBBB
    return url;
    } // podi 3 End
    } //public class eka ***
    // End of program
    output comes as below:
    Isbn:
    Title:
    Price:
    Author:
    Message was edited by:
    chandanal

    Hi Chandanal,
    I edited your code slightly and I was able to get the correct output.
    I changed the following line:
    for (int j=0; j >< len; j++)to:
    for (int j=0; j < len; j++)I have included the complete source below:
    // menna puthe DOMSample eka - duwanawa 19/12/2005
    import java.io.*;
    import java.net.*;
    import org.w3c.dom.*;
    import org.w3c.dom.Node;
    import oracle.xml.parser.v2.*;
    public class DOMSample {
        //public class eka ***
        public static void main(String[] argv) {
            // main method eka ###
            try {
                if (argv.length != 1) {
                    // Must pass in the name of the XML file...
                    System.err.println("Usage: java DOMSample filename");
                    System.exit(1);
                // Get an instance of the parser
                DOMParser parser = new DOMParser();
                // Generate a URL from the filename.
                URL url = createURL(argv[0]);
                // Set various parser options: validation on,
                // warnings shown, error stream set to stderr.
                parser.setErrorStream(System.err);
                parser.showWarnings(true);
                // Parse the document.
                parser.parse(url);
                // Obtain the document.
                Document doc = parser.getDocument();
                // Print document elements
                System.out.print("The elements are: ");
                printElements(doc);
                // Print document element attributes
                System.out.println("The attributes of each element are: ");
                printElementAttributes(doc);
            } catch (Exception e) {
                System.out.println(e.toString());
        // main method eka ###
        static void printElements(Document doc) {
            NodeList nl = doc.getElementsByTagName("*");
            Node n;
            for (int i = 0; i < nl.getLength(); i++) {
                n = nl.item(i);
                System.out.print(n.getNodeName() + " ");
            System.out.println();
        static void printElementAttributes(Document doc) {
            NodeList nl = doc.getElementsByTagName("*");
            Element e;
            Node n;
            NamedNodeMap nnm;
            String attrname;
            String attrval;
            int i, len;
            len = nl.getLength();
            for (int j = 0; j < len; j++) {
                e = (Element)nl.item(j);
                System.out.println(e.getTagName() + ":");
                nnm = e.getAttributes();
                if (nnm != null) {
                    for (i = 0; i < nnm.getLength(); i++) {
                        n = nnm.item(i);
                        attrname = n.getNodeName();
                        attrval = n.getNodeValue();
                        System.out.print(" " + attrname + " = " + attrval);
                System.out.println();
        static URL createURL(String filename) {
            // podi 3 Start
            URL url = null;
            try {
                url = new URL(filename);
            } catch (MalformedURLException ex) {
                /// BBBBBB
                try {
                    File f = new File(filename);
                    url = f.toURL();
                } catch (MalformedURLException e) {
                    System.out.println("Cannot create URL for: " + filename);
                    System.exit(0);
            // BBBBBB
            return url;
        // podi 3 End
    } //public class eka ***-Blaise

  • Context change by DOM parsing Java Mapping in XI

    Hi Team,
    I would like to know that how can I handle Context Change by DOM Parser Java Mapping in XI.?
    Suppose  the source XML structure I have like below:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Header xmlns:ns0="urn:bp:xi:hr:edm:test:100">
       <FileName>
          <filesub>
             <subname>a</subname>
             <subname>b</subname>
             <subname>c</subname>
          </filesub>
       </FileName>
       <FileName>
          <filesub>
             <subname>d</subname>
             <subname>e</subname>
             <subname>f</subname>
          </filesub>
       </FileName>
    </ns0:Header>
    Where the field FileName can occur maximum thrice(0...3) but the subname field is (0....unbounded) but in the target source I would like to have as given below:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <MT_Test4 xmlns="urn:bp:xi:hr:edm:test:100">
    - <Header>
      <FileName>a</FileName>
      <FileName1>d</FileName1>
        </Header>
    - <Header>
      <FileName>b</FileName>
      <FileName1>e</FileName1>
       </Header>
    Header>
      <FileName>c</FileName>
      <FileName1>f</FileName1>
       </Header>
    </MT_Test4>
    That means the first value from every context of the source field is forming my first and second value in my target first context.Thensecond value from every context is forming my 1st and 2nd value of my target 2nd context and finally 3rd value of every context is forming my 1st and 2nd value of my target 3rd context.Is this possible to done through DOM parsing or we have to do it by UDF only?

    Hi Atanu,
        In my last post I gave an alogorithm to solve the mapping problem. Here is the complete program for the mapping.
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    public class DOMParser1  implements StreamTransformation{
         public void execute(InputStream in, OutputStream out)
                   throws StreamTransformationException {
              try
                   DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
                   DocumentBuilder builderel=factory.newDocumentBuilder();
                   /input document in form of XML/
                   Document docIn=builderel.parse(in);
                   /document after parsing/
                   Document docOut=builderel.newDocument();
                   TransformerFactory tf=TransformerFactory.newInstance();
                   Transformer transform=tf.newTransformer();
                   Element root,child,child1=null;
                   Node textChild;
                   NodeList l;
                   int i,n1,j,div,k;
                   String s[];
                   root=docOut.createElement("MT_Test4");
                   root.setAttribute("xmlns","urn:bp:xi:hr:edm:test:100");
                   l=docIn.getElementsByTagName("subname");
                   n1=l.getLength();
                   s=new String[n1];
                   for(i=0;i<n1;++i)
                             s<i>=l.item(i).getFirstChild().getNodeValue();
                   l=docIn.getElementsByTagName("filesub");
                   div=l.getLength();
                   j=n1/div;
                   for(i=0,k=0;i<j;++i)
                        child1=docOut.createElement("Header");
                        root.appendChild(child1);
                        child=docOut.createElement("FileName");
                        textChild=docOut.createTextNode(s[k]);
                        child.appendChild(textChild);
                        child1.appendChild(child);
                        child=docOut.createElement("FileName1");
                        textChild=docOut.createTextNode(s [ k + j ]);
                        child.appendChild(textChild);
                        child1.appendChild(child);
                        ++k;
                   docOut.appendChild(root);
                   transform.transform(new DOMSource(docOut), new StreamResult(out));     
              catch(Exception e)
                   e.printStackTrace();
         public void setParameter(Map arg0) {
         public static void main(String[] args) {
              try{
                   DOMParser1 genFormat=new DOMParser1();
                   FileInputStream in=new FileInputStream("C:/Apps/my dw/sdnq/apps.xml");
                   FileOutputStream out=new FileOutputStream("C:/Apps/my dw/sdnq/tgt1.xml");
                   genFormat.execute(in,out);
              catch(Exception e)
                   e.printStackTrace();
    source ->  apps.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:Header xmlns:ns0="urn:bp:xi:hr:edm:test:100">
    - <FileName>
    - <filesub>
      <subname>a</subname>
      <subname>b</subname>
      <subname>c</subname>
      </filesub>
      </FileName>
    - <FileName>
    - <filesub>
      <subname>d</subname>
      <subname>e</subname>
      <subname>f</subname>
      </filesub>
      </FileName>
      </ns0:Header>
    target structure ->  tgt1.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    - <MT_Test4 xmlns="urn:bp:xi:hr:edm:test:100">
    - <Header>
      <FileName>a</FileName>
      <FileName1>d</FileName1>
      </Header>
    - <Header>
      <FileName>b</FileName>
      <FileName1>e</FileName1>
      </Header>
    - <Header>
      <FileName>c</FileName>
      <FileName1>f</FileName1>
      </Header>
      </MT_Test4>
    Hope this helps
    one more thing  in this line "textChild=docOut.createTextNode(s k + j );"   somehow the the third braces one opening  before k and one closing after j is missing for unknown reasons. Please correct it when you actually run this code.
    regards
    Anupam
    Edited by: anupamsap on Mar 7, 2011 12:47 PM

  • DOM Parsing problems... (newbie in trouble)

    I am trying to get a DOM Parser contruct a DOM Object from an XML file... I am having trouble getting the code validate against my XML Schema: <p>
    <?xml version="1.0" encoding="UTF-8"?> <
    <!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Fedro E. Ponce de Leon Luengas (ASI Consulores, S.A. de C.V.) -->
    <xs:schema targetNamespace="http://palaciohierro.com.mx/mde/expe" xmlns="http://palaciohierro.com.mx/mde/expe" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="existencia-peticion" type="epType">
    <xs:annotation>
    <xs:documentation>Peticion de existencias para la Mesa de Eventos Web</xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:complexType name="epType">
    <xs:annotation>
    <xs:documentation>peticion de existencia</xs:documentation>
    </xs:annotation>
    <xs:sequence>
    <xs:element name="articulo" type="articuloType" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="articuloType">
    <xs:annotation>
    <xs:documentation>articulo</xs:documentation>
    </xs:annotation>
    <xs:attribute name="id_articulo" type="IdentifierType" use="required"/>
    <xs:attribute name="sku" type="skuType" use="required"/>
    </xs:complexType>
    <xs:simpleType name="IdentifierType">
    <xs:annotation>
    <xs:documentation>identificador</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:long">
    <xs:minInclusive value="0"/>
    <xs:maxInclusive value="999999999999999999"/>
    <xs:totalDigits value="22"/>
    <xs:fractionDigits value="0"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="skuType">
    <xs:annotation>
    <xs:documentation>sku</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
    <xs:minLength value="11"/>
    <xs:maxLength value="20"/>
    <xs:pattern value="\d{11,20}"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>
    taking this sample XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
    <expe:existencia-peticion xmlns:expe="http://palaciohierro.com.mx/mde/expe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://palaciohierro.com.mx/mde/expe
    C:\oracle\Oracle9iDS\jdev\mywork\testCompra\MesaEventos\src\ph\mesaeventos\schema\existencia-peticion.xsd">
    <articulo id_articulo="450" sku="12245110021"/>
    <articulo id_articulo="15" sku="45421213223"/>
    <articulo id_articulo="12" sku="121131231858"/>
    <articulo id_articulo="74" sku="4101031234545"/>
    <articulo id_articulo="871" sku="022324563212"/>
    </expe:existencia-peticion>
    with the following code:
    public Document getDOM( String existenciapeticionXML ) throws Exception
    // Obtain parser instance and parse the document
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating( true );
    factory.setNamespaceAware( true );
    DocumentBuilder builder = factory.newDocumentBuilder();
    byte buf[] = existenciapeticionXML.getBytes();
    ByteArrayInputStream stream = new ByteArrayInputStream( buf );
    Document doc = builder.parse( stream );
    return doc;
    I am getting the following Exception:
    oracle.xml.parser.v2.XMLParseException: Element 'expe:existencia-peticion' used but not declared.
    void oracle.xml.parser.v2.XMLError.flushErrors()
    XMLError.java:145
    void oracle.xml.parser.v2.NonValidatingParser.parseDocument()
    NonValidatingParser.java:263
    void oracle.xml.parser.v2.XMLParser.parse(org.xml.sax.InputSource)
    XMLParser.java:141
    org.w3c.dom.Document oracle.xml.jaxp.JXDocumentBuilder.parse(org.xml.sax.InputSource)
    JXDocumentBuilder.java:96
    org.w3c.dom.Document javax.xml.parsers.DocumentBuilder.parse(java.io.InputStream)
    DocumentBuilder.java:119
    org.w3c.dom.Document ph.mesaeventos.mesa.xml.ExistenciaPeticionDOM.getDOM(java.lang.String)
    ExistenciaPeticionDOM.java:26
    void ph.mesaeventos.mesa.xml.Test.main(java.lang.String[])
    Test.java:38
    What am I doing wrong? I am clueless... please help!
    Thanks,

    I finally managed to make it work.... well quite!
    Having an XML Doc like this:
    <?xml version="1.0"?>
    <existencia-peticion xmlns = "http://palaciohierro.com.mx/mde/expe">
    <articulo id_articulo="10" sku="00000000010"></articulo>
    <articulo id_articulo="11" sku="00000000011"></articulo>
    <articulo id_articulo="12" sku="00000000012"></articulo>
    <articulo id_articulo="13" sku="00000000013"></articulo>
    </existencia-peticion>
    with an schema like:
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://palaciohierro.com.mx/mde/expe"
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:expe="http://palaciohierro.com.mx/mde/expe"
    elementFormDefault="qualified">
    <annotation>
    <documentation xml:lang="es">
    Esquema de peticion de existencias para la Mesa de Eventos Web
    Copyright 2002 palaciodehierro.com.mx. Todos los derechos reservados.
    </documentation>
    </annotation>
    <element name="existencia-peticion" type="expe:epType">
    <unique name="id_articulo">
    <selector xpath="expe:articulo"/>
    <field xpath="@id_articulo"/>
    </unique>
    <unique name="sku">
    <selector xpath="expe:articulo"/>
    <field xpath="@sku"/>
    </unique>
    </element>
    <complexType name="epType">
    <annotation>
    <documentation>peticion de existencias</documentation>
    </annotation>
    <sequence>
    <element name="articulo" type="expe:articuloType" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    <complexType name="articuloType">
    <annotation>
    <documentation>articulo</documentation>
    </annotation>
    <attribute name="id_articulo" type="expe:IdentifierType" use="required"/>
    <attribute name="sku" type="expe:skuType" use="required"/>
    </complexType>
    <simpleType name="IdentifierType">
    <annotation>
    <documentation>identificador</documentation>
    </annotation>
    <restriction base="long">
    <minInclusive value="0"/>
    <maxInclusive value="999999999999999999"/>
    <totalDigits value="18"/>
    <fractionDigits value="0"/>
    </restriction>
    </simpleType>
    <simpleType name="skuType">
    <annotation>
    <documentation>sku</documentation>
    </annotation>
    <restriction base="string">
    <minLength value="11"/>
    <maxLength value="20"/>
    <pattern value="\d{11,20}"/>
    </restriction>
    </simpleType>
    </schema>
    and with the following class:
    public class XMLValidator
    // Instancia singleton
    private static XMLValidator validator = new XMLValidator();
    * Constructor privado
    private XMLValidator()
    * Mitodo para acceder a la instancia Singleton de XMLValidator
    * @regresa <b>XMLValidator</b> La instancia de esta clase
    public static XMLValidator getValidator()
    return validator;
    public boolean validaEsquema( String docXML, String esquema ) throws Exception
    // Establece el URL correcto para el documento de esquema
    XSDBuilder builder = new XSDBuilder();
    URL url = createURL( esquema );
    // Construye el objecto del Schema XML
    try
    XMLSchema schemadoc = (XMLSchema)builder.build( url );
    // Valida el documento XML procesandolo contra el esquema
    return validate( docXML, schemadoc );
    catch( XMLParseException e )
    throw new Exception( "Error al analizar el documento XML: " + e.getMessage() );
    catch( Exception e )
    throw new Exception( "No es posible validar con el esquema: " + e.getMessage() );
    private static boolean validate(String docXML, XMLSchema schemadoc) throws Exception
    boolean isValid = false;
    // Crea un objeto Parser DOM de XML
    DOMParser dp = new DOMParser();
    // Establece el objeto Schema XML para la validacion
    dp.setXMLSchema( schemadoc );
    dp.setValidationMode( XMLParser.SCHEMA_VALIDATION );
    dp.setPreserveWhitespace( true );
    // Establece la salida de errores
    dp.setErrorStream( System.out );
    // Recupera los datos del documento XML en un objeto InputStream
    byte[] docbytes = docXML.getBytes();
    ByteArrayInputStream in = new ByteArrayInputStream( docbytes );
    // Parsea el documento y validalo contra el esquema
    try
    dp.parse( in );
    isValid = true;
    catch( Exception e )
    // Devuelve el documento XML DOM construido durante el parseo
    return isValid;
    I am able to validate when invoking with the XML and schemas in the parameters...
    Problem is that I have to include the attribute xmlns = "http://palaciohierro.com.mx/mde/expe" in my XML doc.
    What I really need is to be able to validate de XML doc against a stablished schema, when the XML doc does not include the
    xmlns attribute.

  • DOM Parsing Not working in Applet.

    Hi,
    I ve an applet (parserapplet)which contains the DOM parsing. So xalan.jar(nearly 780 kb) required to assist the parsing. I gave archive="xalan.jar" in My html file. But the jar file is not downloaded from the archive tag. and ClassnotFoundException is thrown.
    the exact exception is:
    ======================
    com.ms.security.SecurityExceptionEx[Host]: cannot access file C:\WINNT\Java\lib\jaxp.properties
         at com/ms/security/permissions/FileIOPermission.check
         at com/ms/security/PolicyEngine.deepCheck
         at com/ms/security/PolicyEngine.checkPermission
         at com/ms/security/StandardSecurityManager.chk
         at com/ms/security/StandardSecurityManager.checkRead
         at java/io/File.exists
         at javax/xml/parsers/DocumentBuilderFactory.findFactory
         at javax/xml/parsers/DocumentBuilderFactory.newInstance
         at parserapplet.parseXMLMessage
         at parserapplet.init
         at com/ms/applet/AppletPanel.securedCall0
         at com/ms/applet/AppletPanel.securedCall
         at com/ms/applet/AppletPanel.processSentEvent
         at com/ms/applet/AppletPanel.processSentEvent
         at com/ms/applet/AppletPanel.run
         at java/lang/Thread.run
    javax.xml.parsers.FactoryConfigurationError: java.lang.ClassNotFoundException: org/apache/crimson/jaxp/DocumentBuilderFactoryImpl
         at javax/xml/parsers/DocumentBuilderFactory.newInstance
         at parserapplet.parseXMLMessage
         at parserapplet.init
         at com/ms/applet/AppletPanel.securedCall0
         at com/ms/applet/AppletPanel.securedCall
         at com/ms/applet/AppletPanel.processSentEvent
         at com/ms/applet/AppletPanel.processSentEvent
         at com/ms/applet/AppletPanel.run
         at java/lang/Thread.run
    I know signing the applet a bit. But though it is signed , second exception is constantly thrown. so please write in detail the procedure to sign the applet. and how to download xalan.jar in html page etc.,
    I require how to download the jar files, and after the completion of downloading of the jar files only, the applet should get executed. or shall i use different jar file(like crimson.jar?). This is urgent requirement.Please help me.!
    the classes for the parsing are not at all downloaded and hence the problem.
    help me reg that.
    thank you in advance/.
    Prasanna kumar k.

    Hello Prasanna kumar k.
    First you should sign your jar files (xerces.jar crimson.jar and xalan.jar) and recreate a cab files
    xerces.cab crimson.cab xalan.cab. To do that you should download sdk for java from microsoft .
    create testkey named testkey.pvk
    1. makecert -sv testkey.pvk -n "CN=your name" test.cer
    convert to public key
    2. cert2spc test.cer test.spc :
    create cab file
    3. cabarc -p -c -r -s 6144 test.cab
    sign the cab file
    4. signcode -j java.dll -jp -low -spc -v testkey.pvk -n test.cab
    after that you should use thia files in html:
    <!doctype html public "//W3//DID HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <META content="text/html; charset=iso-8859-1">
    <TITLE>IBM Host On-Demand 6.0</TITLE>
    </HEAD>
    <BODY BACKGROUND="mankolpr/custom/img/Drawing1.gif">
    <CENTER>
    <IMG src="mankolpr/custom/img/images/ot_hod_log.gif">
    <P>
    <APPLET archive="crimson.jar,xerces.jar,xalan.jar" CODE="test.class" WIDTH=584 HEIGHT=450>
    <PARAM NAME=cabinets VALUE=crimson.cab,xerces.cab,xalan.cab>
    <PARAM NAME=background VALUE="pink">
    <p>If you are reading this message, your client platform is not capable of running
    IBM Host On-Demand. To run IBM Host On-Demand, you must have a Java-enabled web
    browser such as Netscape Navigator or Microsoft Internet Explorer.
    </APPLET>
    </CENTER>
    </BODY>
    </HTML>
    Best Regards,
    Tzur Emzari
    Project Manager
    Local Authority Data Processing Center LTD
    ISRAEL
    Tel : 972-4-8615754, Fax : 972-4-8661977
    Cell : 972-53-532448
    [email protected] <mailto:[email protected]>

  • XML Validation using XDK SAX/DOM Parser

    Hello,
    I am trying to validate xml against xsd using SAX/DOM parser, both the files are stored as CLOB column in the database. I have the requirement to report all the validation errors and based on some helpful advice/code from the earlier posts in this forum, I have used the following code to validate and report the errors.
    The code works fine but for large files it never goes beyond a certain number of errors i.e. getNumMessages() (XMLParseException) never returns value greater than 100 and thus limits the output of the validation errors. Any pointers to suggest change in code or an alternative will be extremely helpful.
    Datebase Version : Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED <> as package <package name>;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.sql.SQLException;
    import oracle.sql.CLOB;
    import oracle.xml.parser.schema.*;
    import oracle.xml.parser.v2.*;
    import org.w3c.dom.*;
    public class XMLSchemaVal
    public static String validate(CLOB xmlDoc, CLOB xsdDoc)
    throws Exception
    //Build Schema Object
    XSDBuilder builder = new XSDBuilder();
    Reader xsdInUnicodeFormat = xsdDoc.getCharacterStream();
    XMLSchema schemadoc = (XMLSchema)builder.build(xsdInUnicodeFormat, null);
    //Build XML Object
    Reader xmlInUnicodeFormat = xmlDoc.getCharacterStream();
    // Genereate the SAX
    SAXParser saxparser_doc = new SAXParser();
    // Set Schema Object for Validation
    saxparser_doc.setXMLSchema(schemadoc);
    saxparser_doc.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    saxparser_doc.setPreserveWhitespace (true);
    String returnValue;
    try {
    saxparser_doc.parse (xmlInUnicodeFormat);
    returnValue = "The input XML parsed without errors.\n";
    catch (XMLParseException se) {
    returnValue = "Parser Exception: ";
    for (int i=0 ; i < se.getNumMessages(); i++)
    returnValue += "<LN: " + se.getLineNumber(i) + ">: " + se.getMessage(i);
    //returnValue = "Parser Exception: " + se.getNumMessages();
    catch (Exception e) {
    returnValue = "NonParserException: " + e.getMessage();
    return returnValue;
    Function to call the above utility from PL/SQL
    CREATE OR REPLACE FUNCTION F_XMLSCHEMAVALIDATION (P_XML IN clob ,P_XSD IN clob) RETURN VARCHAR2 IS
    LANGUAGE JAVA NAME XMLSchemaVal.validate(oracle.sql.CLOB,oracle.sql.CLOB) return java.lang.String';
    Thanks.

    Got the answer !!!
    NetBeans it self support generation of dtd file based on XML file.
    Open XML file and right click on the code block. Select option to generate dtd file.
    This is the drtd file it has generated..
    <?xml version='1.0' encoding='UTF-8'?>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT book (person)*>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT person (age|last|first)*>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT first (#PCDATA)>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT last (#PCDATA)>
    <!--- Put your DTDDoc comment here. -->
    <!ELEMENT age (#PCDATA)>

  • How to manipulate object mapping runtime using DOM parser in java?

    Scenario: We will be getting logical name of the table from which we have to fetch the details. We have few tables which have more or less same columns, the only difference is the prefix. Say we have Tables: Temp1 and Temp2 contains column as Temp1Col1 and Temp2Col1. I dont want to go with creating as many POJO classes in java as that of tables. So i will create only one POJO class with common attributes and at runtime i want to change the object mapping file of Hibernate to hold table values. I have an idea that this can be done using DOM parser. But it would be great if somebody can share the java code for the same.
    Thanks in advance.

    SAX is a parser, not a generator.Well,
    you can use it to create an XML file too. And it will take care of proper encoding, thus being much superior to a normal textwriter:
    See the following code snippet (out is a OutputStream):
    PrintWriter pw = new PrintWriter(out);
          StreamResult streamResult = new StreamResult(pw);
          SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
          //      SAX2.0 ContentHandler.
          TransformerHandler hd = tf.newTransformerHandler();
          Transformer serializer = hd.getTransformer();
          serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"pdfBookmarks.xsd");
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://schema.inplus.de/pdf/1.0");
          serializer.setOutputProperty(OutputKeys.METHOD,"xml");
          serializer.setOutputProperty(OutputKeys.INDENT, "yes");
          hd.setResult(streamResult);
          hd.startDocument();
          //Get a processing instruction
          hd.processingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"mystyle.xsl\"");
          AttributesImpl atts = new AttributesImpl();
          atts.addAttribute("", "", "someattribute", "CDATA", "test");
          atts.addAttribute("", "", "moreattributes", "CDATA", "test2");
           hd.startElement("", "", "MyTag", atts);
    String curTitle = "Something inside a tag";
              hd.characters(curTitle.toCharArray(), 0, curTitle.length());
        hd.endElement("", "", "MyTag");
          hd.endDocument();
    You are responsible for proper nesting. SAX takes care of encoding.
    Hth
    ;-) stw

  • Very Urgent Please Help Me with XML parsing(DOM parser)

    Hi
    Please help me with the following code.
    I have an XML file
    <catalog>
    <book id="101">
    <title>First Ex With ID 101</title>
    <ID>500</ID>
    <author>RAJU</author>
    <price>39.95</price>
    </book>
    <book id="121">
    <ID>501</ID>
    <title>First Ex With ID 121</title>
    <author>RAJU1</author>
    <price>19.95</price>
    </book>
    </catalog>
    By using DOM parser I have to retrive ID values .After getting this ID values i have to pass these values in someother method of someother class.What i suppose to do?Can anyone help me with this regards ,if possible plese write the code..
    Regards
    Raju G

    Well first up all create a parser class where u parse the document using DOm and get the id node and assigen it to a String sat str.
    Now whatever processiong u want to do , u write in a separate class (say Process.java) in one method say doProcess(String str)
    Now from parser class u just call the doProcess() method with passing str as a parameter.
    eg.
    Process p = new Process();
    p.doProcess(str);
    Hope this will help u.
    ....yogesh

  • DOM Parser fails with regular expression using anchor (carat, dollar)

    I'm using version "Oracle XDK Java 9.0.4.0.0 Production"
    In trying to parse XML against schema: a regular expression fails to parse the data "8:00" with the following simple regular expression: "^.*$" (used to narrow the error)
    The error message is
    <Line 14, Column 25>: XSD-2025: (Error) Invalid text '8:00' in element: 'XYZ'
    If I remove the anchors and just have ".*", the data is parsed successfully.
    I dont understand why the parse fails when I use a anchors in the regular expression, and the java Pattern/Matcher classes succeed with the anchors?

    That "ns670" string is an xml namespace prefix. it should have a corresponding xml namespace declaration somewhere in the xml document (i'm guessing you have not shown the whole document). the actual value of an xml namespace prefix is meaningless. if you parse the xml with a namespace aware DOM parser, it should generate Nodes with the correct namespace. the namespace is the value you care about when extracting data from the document, not the namespace prefix.
    alternately, if you parse the document using a namespace aware DOM parser, you can just look for nodes based on their "local" name (the part after the ":" separator) and ignore the namespace/prefix.
    whatever you do, please do not parse the xml with a regex, see this http://stackoverflow.com/a/1732454/552759 for details (applies to xml as well).

  • Strange Problem about Dom Parser

    Hi, all
    I am using Dom parser to extract content from one xml file, and it works this afternoon, then tonight when i tried to run again, it gives me an exception:
    org.xml.sax.SAXParseException: Document root element "Total", must match DOCTYPE root "null".
    In my xml file, i don't have <!DOCTYPE ....>, but it is the same xml file i run this afternoon, also, as far as i know, <!DOCTYPE> is not necessary, right?
    Please help me, really frustrated here!

    The parser class only supports a class derived from the java.io.Reader class. I am not sure if there is a class that derives from such that would handle a url string. You may need to obtain the file using java.net for the url and then pass that to a FileReader object.
    One thing that i just thought of that might work is this:
    parser.parse(new File(url));

Maybe you are looking for

  • Works on dev, but not production server

    I am building a site using LCCS which works on my laptop, which runs ColdFusion 9 and Apache. But it does not work on my production server, which is ColdFusion 8 and IIS. I have made the various configuration changes and I can successfully create a r

  • Icloud alternative E mail address

    As usual, I'm struggling with security issues. Today it's icloud. Having wasted a huge amount of my morning, I am finally back in my icloud account. One of the main reasons I was having trouble was because my 'alternitive' E mail address was the same

  • Output report XML very slow

    Hi, I designed the report output includes 40 columns and 100000 rows. However, the request and opens slow in XML format on the client very slow. Please ask you one optimal solution to the problem above? (Version R12) Thank alot! Edited by: user121933

  • Write multiple devices data into columns

    Hi, I have a problem in writing data from 2 devices that i currently have (for pressure and temperature). I wanted it to be written in 2 coloums, one for temperature and one for pressure for each data produced. What i currently have is that the data

  • Bloggie MHS-TS10 /TS20 EXPORTING to bloggie help me

    ok so i just bought bloggie mhs-ts10 i have no trouble exporting videos to my bloggie i have imported from my bloggie.. but when i try to convert other vids i have that were not associated with the blogie i get an error... the non associated videos w