java - Correct way to construct this xml using Xstream -


i'm trying achieve following using xstream:

<?xml version="1.0" encoding="utf-8"?> <rows>     <row id="eventid">         <cell>false</cell>         <cell>mainland</cell>         <cell></cell>         <cell></cell>          <row id = "storeid">             <cell></cell>             <cell></cell>             <cell></cell>             <cell></cell>         </row>      </row> </rows> 

here can see row id of "storeid" child row of "eventid" row. can create both seperately doing following:

    string xml = "", eventxml = "", storexml = "";     stringbuffer buff = new stringbuffer(1000);     buff.append("<?xml version='1.0' encoding='iso-8859-1'?>");      xstream xstream = new xstream(new domdriver());       xstream.alias("rows", list.class);     xstream.alias("row", event.class);      xstream.registerconverter(evtconverter);      for( event e: events )     {         // list of stores         store store = e.getstore();         xstream.registerconverter( storeconverter, xstream.priority_very_high );          xstream.alias("row", store.class);         storexml = xstream.toxml( store );          xml = xstream.toxml(e);     }     return xml; 

so how can go combining them? there way stop automatic closure of xml (the event object) can add in store xml?

thanks

to had dilute down basic strings. created method combines xml strings together:

private static string combinestrings(string eventxml, string storexml) {     string newxml = "";      pattern pattern = pattern.compile("</row>");     matcher matcher = pattern.matcher(eventxml);      int posforstorexml = 0;      boolean found = false;     while (matcher.find()) {         posforstorexml = matcher.start() - 1;         found = true;     }     if (!found) {         system.err.println("no match found");     }      stringbuilder builder = new stringbuilder(eventxml);     builder.insert(posforstorexml, storexml);      system.out.println(builder.tostring());     newxml = builder.tostring();      return newxml; } 

this had called here:

for (event_backup e : events) {         // list of stores         store store = e.getstore();         xstream.registerconverter(storeconverter,                 xstream.priority_very_high);         xstream.alias("row", store.class);          storexml = xstream.toxml(store);         xml = xstream.toxml(e);         **xml = combinestrings(xml, storexml);**          buffer.append(xml);     }     buffer.append( "</rows>" );     xml = buffer.tostring(); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -