-1

I'm trying to merge/combine two xml strings that I got from parsing an object to XML using castor marshalling/unmarshalling. Here are the two XML strings that I have:

<?xml version="1.0" encoding="UTF-8"?>
<abc:abcResponse xmlns:abc="http://www.abc.com/schema/abcTransaction">
    <abc:code>0</abc:code>
    <abc:description>blah</abc:description>
</abc:abcResponse>

<?xml version="1.0" encoding="UTF-8"?>
<abc:abcRequest xmlns:abc="http://www.abc.com/schema/abcTransaction">
    <abc:id>99999</abc:id>
    <abc:idString>abc</abc:idString>
</abc:abcRequest>

I want to be able to combine these two strings into one so I can insert this into my database (MSSQL) column that has data type XML. I tried using the solution suggested from this link java merge two xml strings in java, but it doesn't seem to recognize it as a valid XML string since no records were inserted into the database table, and there's this error in my console:

com.microsoft.sqlserver.jdbc.SQLServerException: XML parsing: line 1, character 12,   text/xmldecl not at the beginning of input

If I insert either of these strings separately into the database column then a new record will be added just fine.

Anyone has a good idea as to how to do this properly? Much thanks!

Community
  • 1
  • 1
user974047
  • 2,115
  • 7
  • 33
  • 45
  • possible duplicate of [java merge two xml strings in java](http://stackoverflow.com/questions/3208241/java-merge-two-xml-strings-in-java) –  Jul 17 '13 at 14:22
  • this is not a duplicate since what was done there cannot be applied to my question – user974047 Jul 17 '13 at 14:33

1 Answers1

4

You should create something like the following ("abcTransaction" is a wild guess).

<?xml version="1.0" encoding="UTF-8"?>
<abc:abcTransaction xmlns:abc="http://www.abc.com/schema/abcTransaction">
    <abc:abcRequest>
        <abc:id>99999</abc:id>
        <abc:idString>abc</abc:idString>
    </abc:abcRequest>
    <abc:abcResponse>
        <abc:code>0</abc:code>
        <abc:description>blah</abc:description>
    </abc:abcResponse>
</abc:abcTransaction>

Maybe even leaving out the xmlns and "abc:" parts.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138