1

I have an xml ans i want to make it objects , i am using xsteam for this and I have added xstream jars in my classpath..

below is my xml...

<Eurexflows xmlns:eur="http://www.eurexchange.com/EurexIRSFullInventoryReport" xmlns:fpml="http://www.fpml.org/FpML-5/confirmation">
<EurexMessageObject>
<CCPTradeId>109599</CCPTradeId>
<novDateTime>2012-02-15 10:59:00.0</novDateTime>
</EurexMessageObject>
<EurexMessageObject>
<CCPTradeId>122270</CCPTradeId>
<novDateTime>2012-06-29 18:59:00.0</novDateTime>
</EurexMessageObject>
</Eurexflows>

below is my pojo...

public class EurexMessageObject {

    private Long CCPTradeId;
    private String migratedDate;

    public Long getCCPTradeId() {
        return CCPTradeId;
    }

    public void setCCPTradeId(Long cCPTradeId) {
        CCPTradeId = cCPTradeId;
    }

    public String getMigratedDate() {
        return migratedDate;
    }

    public void setMigratedDate(String migratedDate) {
        this.migratedDate = migratedDate;
    }


}

and in my main class I have coded this way..

String xmlInputtra="C:\\Rahul\\InputXml\\Xmloutput.xml";
         try
         {

      // get XStream instance and set required aliases
            XStream xstream = new XStream();
            xstream.alias("EurexMessageObject", com.rbos.gdspc.eurex.EurexMessageObject.class);
            // prepare cash flow message from xslt output
            EurexMessageObject eurexflowMsg = (EurexMessageObject) xstream.fromXML(xmlInputtra);
            System.out.println(eurexflowMsg.toString());

         }catch(Exception e)
         {
             e.printStackTrace();
         }

now upon debuging I am getting the following exception..please advise how can I overcome from this

com.thoughtworks.xstream.io.StreamException:  : only whitespace content allowed before start tag and not C (position: START_DOCUMENT seen C... @1:1) 
1
  • You should put in the var xmlInputtra a xml not a path. Commented Dec 17, 2014 at 9:44

2 Answers 2

2

Well,the thing that is overlooked here is how you are reading in the XML file.you are using the method fromXML which is expecting the actual XML input and not the file name. So when it parses your xml (which is "Xmloutput.xml" not the actual xml)

I suggest you to use a FileReader/BufferedReader in order to get the contents of the XML back. Something like this should work:

XStream instream = new XStream();

BufferedReader br = new BufferedReader(new FileReader("Xmloutput.xml"));
StringBuffer buff = new StringBuffer();
String line;
while((line = br.readLine()) != null){
   buff.append(line);
}
EurexMessageObject eurexflowMsg = (EurexMessageObject)instream.fromXML(buff.toString());

I hope it will help you, best regards.

Sign up to request clarification or add additional context in comments.

Comments

0

Here path for XML file:

String xmlInputtra="C:\\Rahul\\InputXml\\Xmloutput.xml";

is treated as XML contents, so you need to pass as String for that you can read file and pass to constructor.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.