How to parse multiple xml documents from single buffer

Hello,
I am trying to use jaxb 2.0 to parse a buffer which contains multiple xml documents. However, it seems that it is meant to only parse a single document at a time and throws an exception when it gets to the 2nd document.
Is there a way I can tell jaxb to only parse the first complete document and not fetch the next one out of the buffer? Or what is the most efficient way to separate the buffer into two documents without parsing it manually. If I have to search the buffer for the next document root and then split the buffer, it seems like that defeats the purpose of using jaxb as the parser.
I am using the Unmarshaller.unmarshall method and the exception I am getting is:
org.xml.sax.SAXParseException: Illegal character at end of document, <.]
     at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
     at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:476)
     at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:198)
     at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:167)
     at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
     at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
Thank you for your help

It's just like any other XML parser, it's only designed to parse one XML document. If you have something that concatenates two XML documents together (that's what your "buffer" sounds like), then stop doing that.

Similar Messages

  • How to create an XML document from a String.

    Can anyone help,
         In the Microsoft XML Document DOM there is a load function load(string) which will create an XML document, but now we are switching to Java and I do not know how to create and XML document from a string, this string �xml document� is passed to my program from a webservice and I need to read several xml elements form it in a web server.
    This string is a well formatted XML document:
    <?xml version="1.0" encoding="UTF-8"?>
    <Countries NumberOfRecords="1" LanguageID="en-us">
         <Country>
              <CountryCode>AU</CountryCode>
              <CountryName>AUSTRALIA</CountryName>
         </Country>
    </Countries>

    Thanks PC!
    I made it work using:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    factory.setIgnoringComments(true); // We want to ignore comments
    // Now use the factory to create a DOM parser
    DocumentBuilder parser = factory.newDocumentBuilder();
    //TransformThisStringBuffer is a string buffer wich contain the 'XML document (String)'
    InputStream in = new ByteArrayInputStream(TransformThisStringBuffer.toString().getBytes());
    // Parse the InputStream and build the document
    Document document = parser.parse(in);
    But which one is faster InputSource or InputStream, were would you put the "new InputSource(new StringReader(yourString))" in the above code?

  • How can I access xml document from javascript whithin a JSP page

    how can I access xml document from javascript whithin a JSP page?
    I have a JSP that receives an XML document from a JavaBean, so I can access it within the entire JSP, but I need to access it from the javascript inside the JSP... and I have no idea how i can do this.
    Thanks in advance!

    The solution would only work on MS IE browsers, as other browsers do not support an XML DOM.
    It can be done, but you would be stuck with using the Microsoft broswer. If that is acceptable, I have some example code, and a book recommendation.

  • How to Create an XML document from XSQL servlet which follows a particular DTD struct

    how to Create an XML document from XSQL servlet which follows a particular DTD structure.Could anyone send me a sample code for this.

    You'll need to associate an XSLT transformation with your XSQL page that transforms the canonical result into your DTD-valid format.
    For example, given an XSQL page like:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="rss.xsl" ?>
    <xsql:query max-rows="3" connection="demo" xmlns:xsql="urn:oracle-xsql">
    select title,id,description,url,to_char(timestamp,'Mon DD') timestamp
    from site_entry
    order by id desc
    </xsql:query>and an "rss.xsl" stylesheet that looks like this:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" doctype-system="rss-0.91.dtd"/>
    <xsl:template match="/">
    <xsl:for-each select="ROWSET/ROW">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    <xsl:for-each select="ITEM">
    <item>
    <title><xsl:value-of select="TITLE"/></title>
    <link><xsl:value-of select="URL"/></link>
    <description><xsl:value-of select="DESCRIPTION"/></description>
    </item>
    </xsl:for-each>
    </channel>
    </rss>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>You produce DTD-valid output against the rss-0.91.dtd DTD that looks like:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE rss SYSTEM "rss-0.91.dtd">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>

  • How to call multiple strus actions froma single jsp

    how to call multiple strus actions froma single jsp, and that actions should be automatically called pls help me
    Thanks in advance

    how to call multiple strus actions froma single jsp, and that actions should be automatically called pls help me
    Thanks in advance

  • How to generate multiple idoc's from single appl document

    All,
    Iam looking for a way to generate multiple idoc's from single appl document (sales order). Based on the plant details on line items in the sales order i have to generate multiple idocs, i.e., send one idoc to each plant entered in sales order line items. any help will be appreciated.
    Thanks

    Hi,
    You can create a Z-program and call Function Module  <b>MASTER_IDOC_DISTRIBUTE</b>.
    You can make a call to this FM to send the Idoc as many times as u have plants in your Sales Order.
    You can call FM <b>IDOC_OUTPUT_ORDRSP</b> to fill the IDoc structure.
    Then u can keep the materials of only that plant for which u want to pass on the information.
    Thanks,
    Utsah Garg.

  • How can we forward XML document from Routing Engine to Mapviwer!!!

    Does anyone try to forward XML document from routing engine to Mapviwer. Like spatial coordinate system from Routing engine. Could you help me how to accomplish this problem. Thank much much....

    Just open an HTTP connection to MapViewer's server url (ususally http://host:port/mapviewer/omserver) and send an XML map request to it using POST. You can do that from any language that supports such a connection.
    Inside the xml map request you can attach the routing result (a series of coordinates i imagine) as dynamic geo-features. You can also specify any base map/layer information in the xml map req provided you have defined such map/themes. DTD of mapviewer's map req is in the Users Guide, which is on OTN site mapviewer http://otn.oracle.com/products/mapviewer.

  • Parsing an xml data from a buffer

    I have an XML file loaded into a string buffer in java. I would like to know if I can parser XMl data from that buffer using the SAX parser. I do not want to load the xml using the parser, I would like to load the buffer instead.
    Thanks in advance,
    Sudheer.

    StreamSource ss = new StreamSource(new StringReader(myString));
    transformer.transform(ss, new StreamResult(outputFile));

  • How to generate an XML Document from XQuery

    The following query returns me the required XML output. However, I need to generate an XML Document out of it. How do I go about generating an XML Doc?.
    SELECT XMLQuery('<Data>
    {for $tert in ora:view("DATA"),
               $tert_audit in ora:view("DATA_AUDIT")
           let $tert_cmd_id := $tert/ROW/ID/text(),
               $tert_spouse_name := $tert/ROW/SPOUSE_NAME/text(),
               $tert_directions := $tert/ROW/DIRECTIONS/text(),
               $tert_soil_zone := $tert/ROW/SOIL_ZONE/text(),
               $tert_audit_cmd_id := $tert_audit/ROW/ID/text(),
               $tert_audit_trans_date := $tert_audit/ROW/TRANSACTION_DATE/text()
               where $tert_cmd_id = $tert_audit_cmd_id and
               $tert_audit_trans_date >= xs:date(V_Last_Successful_Date)
               order by $tert_cmd_id
           return
           <op>
             <op_type>I</op_type>
             <ent_id>{$tert_cmd_id}</ent_id>
    <source>S</source>
    <fg>
    <val_flds>
    <fld>
    <id>spouse_name</id>
    <val>{$tert_spouse_name}</val>
    </fld>
    <fld>
    <id>directions</id>
    <val>{$tert_directions}</val>
    </fld>
    <fld>
    <id>soil_zone</id>
    <val>{$tert_soil_zone}</val>
    </fld>
    </val_flds>
    </fg>
    </op>}</Data>' RETURNING CONTENT)
    INTO V_Other_Insert
    FROM dual;

    Hi Geoff,
    I would like to generate an XML file which contains data as shown below:
    <Insert>
    <result>
    <type>A</type>
    <id>1</id>
    <date>11/11/2006</date>
    <source>Web</source>
    </result>
    </Insert>
    I'm using the below given query for this purpose:
    SELECT XMLQuery('<Insert>
    {for $c in ora:view("TableA")
           let $id := $c/ROW/ID/text(),
               $code := $c/ROW/CODE/text(),
               $type := $c/ROW/TYPE/text(),
               $date := $c/ROW/DATE/text()
           return
           <result>
             <type>{$type }</type>
    <id>{$id}</id>
    <date>{$date}</date>
    <source>S</source>
    </result> }</Insert>' RETURNING CONTENT)
    INTO V_Insert
    FROM dual;
    V_Insert stores the required result.
    How do I save this result to a XML Document?
    Please help.

  • How to parse an XML document with oracle8i

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

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

  • How to use multiple tape drive from single client when I want to backup single filesystem?

    Hello All.
    I want to backup 1 filesystem using 4 tape drives for reducing backup time.
    In case of symantec veritas netbackup, they can user "NEW_STREAM" for multi-streaming backup.
    Please anybody let me know that how to do use multiple tape drive for single client.
    1. Backup Source server : Linux (1 client)
    2. Backup Soucre :      /data1  (500GB)
        -> Current directory structure doesn't have sub directory under /data1, just files present under /data1
    If direcotry struceture has a sub-direcotry like( /data1/aaa, /data1/bbb ), Is it availble to use multiple tape drives?
    3. Tape Drive with OSB : LTO6 * 4 drives
    Thank you.

    You would have to create a different dataset for each sub-folder. If you only have files at the top level folder then even the NEW_STREAM option couldn't be used to split the job.
    Organise it into folders and then create datasets in a client folder such as :
    /usr/local/oracle/backup/admin/config/dataset/Linux/data1_aaa
    /usr/local/oracle/backup/admin/config/dataset/Linux/data1_bbb
    Then in the schedule you just specify the Linux folder. In each dataset you list the hostname and the folder name, such as :
    include host Linux
    include path /data1/aaa
    Now it will create a new job for each dataset and therefore each folder.
    Thanks
    Rich

  • Servlets and XML - How to Parse the XML Document?

    I would like to create a servlet, which when accessed, will retrieve an
    XML file remotely over the Internet, and parse it to the browser's
    screen.
    Can anyone point to example code that will help me along?
    Thanks.

    Cross post:
    http://forum.java.sun.com/thread.jspa?threadID=5114779&messageID=9391940#9391940

  • [Solved] How to create multiple target nodes from single input node (XSL)

    Hello all,
    I have identified what I think is a bug in the visual XSLT mapper (JDev 10.1.3.3). Here is the simplified scenario:
    I have a source XML file that contains a bill-to address and a ship-to address, something like this:
    <header>
    <bill-to-name>My Customer Bill To</bill-to-name>
    <bill-to-address>123 main street</bill-to-address>
    <ship-to-name>My Customer Ship To</ship-to-name>
    <ship-to-address>567 first avenue</ship-to-address>
    </header>I want to translate it to a target XML file that looks like this:
    <addresses>
    <address>
    <address-type>BILLTO</address-type>
    <name>My Customer Bill To</name>
    <street-address>123 main street</street-address>
    </address>
    <address>
    <address-type>SHIPTO</address-type>
    <name>My Customer Ship To</name>
    <street-address>567 first avenue</street-address>
    </address>
    </addresses>Note that what I am trying to do is to create two nodes in the target (something like a for-each), but where there is no repeating node in the source.
    I was able to do this quite simply with a map like this:
    <xsl:template match="/">
      <ns2:addresses>
        </ns2:address>
          <ns2:address-type>
            <xsl:text disable-output-escaping="no">BILLTO</xsl:text>
          </ns2:address-type>
          <ns2:name>
            <xsl:value-of select="/ns1:header/bill_to_name"/>
          </ns2:name>
          <ns2:street-address>
            <xsl:value-of select="/ns1:header/bill_to_address"/>
          </ns2:name>
        </ns2:address>
        </ns2:address>
          <ns2:address-type>
            <xsl:text disable-output-escaping="no">SHIPTO</xsl:text>
          </ns2:address-type>
          <ns2:name>
            <xsl:value-of select="/ns1:header/ship_to_name"/>
          </ns2:name>
          <ns2:street-address>
            <xsl:value-of select="/ns1:header/ship_to_address"/>
          </ns2:name>
        </ns2:address>
      </ns2:addresses>
    </xsl:template>As long as I only use the source view for the xsl file, this works fine and tests just fine. As soon as I switch over to the graphical (design view), the source gets mangled to:
    <xsl:template match="/">
      <ns2:addresses>
        </ns2:address>
          <ns2:address-type>
            <xsl:text disable-output-escaping="no">BILLTOSHIPTO</xsl:text>
          </ns2:address-type>
          <ns2:name>
            <xsl:value-of select="/ns1:header/bill_to_name"/>
            <xsl:value-of select="/ns1:header/ship_to_name"/>
          </ns2:name>
          <ns2:street-address>
            <xsl:value-of select="/ns1:header/bill_to_address"/>
            <xsl:value-of select="/ns1:header/ship_to_address"/>
          </ns2:name>
        </ns2:address>
      </ns2:addresses>
    </xsl:template>which obviously does not work.
    So:
    1). Should my original map work? If not, what is the correct way to do it?
    2). If the map should work (it does), this looks like a bug in the design view.
    3). If my map should work, is there a way to do this in the design view?
    Kind regards,
    John

    John,
    GUI has limited functionality and hence it does not support all the constructs. If you want to implement soln that is visible in gui follow this steps.
    for-each(bill-to-name)
         create <address>tag
         map concat(BILLTO) to <address-type>
         map value of <bill-to-name> to <name>
         map value of <bill-to-address> to <street-address>
    select the for-each you created - right click -> add xsl node ->clone for-each
         repeat similar steps for mapping <ship-to_name>...etc
    If you still unsure send me the source & target xsd and I will send the xsl your way. You can email me at [email protected]
    Dipal

  • How to use multiple tape drive for single filesystem on single client.

    Hello All.
    I want to backup single filesystem with multiple tape drive.
    Incase of Symantec veritas netbackup "NEW_STREAM" for multi-stream backup.
    Backup client has a  single backup filesystem like /data1  directory with 4 LTO6 drives.
    /data1 directory doesn't have a sub-direcotry, just present a files.
    If /data1 directory has a sub-directory like /data1/aaa, /data1/bbb, /data1/ccc , Is it possible to use multiple drives?
    Please anybody answer the questions.
    Thanks advanced.

    See how to use multiple tape drive from single client when I want to backup single filesystem?

  • Create single XML document from multiple queries

    hi all!
    being a new programmer in XML world,my question might sound a bit stupid but your answers would mean a world to me. i have to generate a single XML document from my database by querying more than one table. for example i have 3 tables i.e HR_EMP_NAME, HR_PRODUCTS_DETAIL, HR_PAYROLL_SUMMARY. all three tables have completely different columns except one ID column which is a foreign kay from HR_MASTER_LIST. i want to get any insert operation on these tables as a single document. so far as i have studied, one option is to generate XMLDoc using XSU and then add child nodes using JAXP but i am ot geting the logic right.
    please do reply.
    thanks a lot
    usman

    This is an SQL/XML based answer so how much it helps you is hard to say, but it would be one option. You can have the SQL statement build the XML for you as shown by this simple example.
    SELECT XMLElement("root",
              XMLForest(emp.dummy AS "emp_name",
                        prod.dummy AS "prod_lvl",
                        pay.dummy AS "pay_scale"))
      FROM dual emp,
           dual prod,
           dual pay
    WHERE emp.dummy = prod.dummy
      AND emp.dummy = pay.dummy;which produces (formatted for human readability)
    <root>
      <emp_name>X</emp_name>
      <prod_lvl>X</prod_lvl>
      <pay_scale>X</pay_scale>
    </root>Whether that works with what you are trying to do via Java you will have to decide.

Maybe you are looking for

  • New Kitkat update has left me w/o sound. +

    So far this is my only problem. The only sound that will work is the ringer and alarm. And yes I have checked all of my settings to make sure nothing is muted or turned off. This all happened right after the update yesterday morning. Please help Sams

  • I need to run something that turns off certain setting, then run something else that turns them back on.

    Hey guys! i just bought a copy of ProTools 11 and it gave some recommendation on changing your default Mac settings to make ProTools run at its peek performance, for example it says to turn on wifi and wired ethernet connection.  There at quite a few

  • Caller can't hear me - Nokia 6233

    One minute everythings fine, the next I can't be heard! I've been through all the menues, and the mike isn't off - tried that too while calling. What can be wrong? Haven't tried to reset or reformate yet, it's my last resort. Please help!

  • JDBC Receiver: exact SQL statement

    Hi, I'm in an IDoc-JDBC scenario, using XML-SQL messages to feed a JDBC Receiver and I am getting <i>weird messages</i> returned by Oracle. Question: is there a way to log/trace/audit <b>the exact SQL statement</b> that my channel is sending to Oracl

  • How to deactivate postings to custom table YFAGLFLEXA

    Hi, We have generated custom YFAGLFLEXT table using FAGLFLEXT as a template. This caused table YFAGLFLEXA to be generated automatically by the system to store the Actual Line Items Postings. Since the YFAGLFLEXA table is not of any utlity to us, we w