Hi Friends,
I am trying to convert a XMLString into idata. using the funcion pasted below. But the function converts the tags into documents. a few tags i need them to be DocumentLists. so i request you all to guide me as to what to include in the xml tags so that the function will recognize it to be a document list and not document.
for eg:
<?xml version="1.0" ?>
<pmtmsgs>
<pmtmsgs>test1</pmtmsgs>
<pmtmsgs>test2</pmtmsgs>
</pmtmsgs>
i need the outer pmtmsgs to be documentlist and the inner pmtmsgs to be docuemnts. Other tags must also be treated as docuemnts.
Function used::::
[highlight=java] public IData getIdata(String st) throws InboundConversionException {
IData idataVal = null;
InputStream xmlstream = new ByteArrayInputStream(st.getBytes());
String xmldata = null;
try {
IData pipeline = IDataFactory.create();
IDataCursor id = pipeline.getCursor();
if (id.first(C_FILEDATA)) {
byte xmlbytes = (byte) id.getValue();
xmlstream = new ByteArrayInputStream(xmlbytes);
} else if (id.first(C_FILE_STREAM)) {
xmlstream = (InputStream) id.getValue();
} else if (id.first(C_XMLDATA)) {
xmldata = IDataUtil.getString(id);
}
String encoding = null;
if (id.first(C_ENCODING)) {
encoding = IDataUtil.getString(id);
}
if (encoding == null || encoding.length() == 0) {
encoding = C_AUTO_DETECT;
} else if (encoding.equalsIgnoreCase(C_AUTO_DETECT)) {
encoding = null;
}
encoding = EncodingNames.getJavaName(encoding);
String expandDTD = null;
if (id.first(C_EXPAND_DTD)) {
expandDTD = IDataUtil.getString(id);
System.out.println("expandDTD "+expandDTD );
}
String isXML = null;
if (id.first(C_ISXML)) {
isXML = IDataUtil.getString(id);
System.out.println("isXML "+isXML);
}
String encodedURL = null;
if (id.first(C_ENCODED_URL)) {
encodedURL = IDataUtil.getString(id);
}
boolean bExpandDTD = expandDTD != null && expandDTD.equals(C_TRUE);
Document node;
if (isXML == null || isXML.equalsIgnoreCase(C_AUTO_DETECT)) {
if (xmldata != null) {
node = new Document(xmldata, encodedURL, encoding,
bExpandDTD);
} else {
node = new Document(xmlstream, encodedURL, encoding,
bExpandDTD);
}
} else if (xmldata != null) {
node = new Document(xmldata, encodedURL, encoding, bExpandDTD,
isXML.equals(C_TRUE));
} else {
node = new Document(xmlstream, encodedURL, encoding,
bExpandDTD, isXML.equals(C_TRUE));
}
if (id.first(C_NODE)) {
id.setValue(node);
} else {
id.last();
id.insertAfter(C_NODE, node);
}
IData in = IDataFactory.create();
DocumentToRecordService dtrs = new DocumentToRecordService(in,
false);
dtrs.setIsXTD(true);
Object val = id.getValue();
Object ret = dtrs.bind((Node) val);
if (ret != null && (ret instanceof IData))
if (id.first(C_DOCUMENT)) {
id.setValue(ret);
} else {
id.last();
id.insertAfter(C_DOCUMENT, ret);
}
idataVal = (IData) id.getValue();
id.destroy();
} catch (WattReferenceException ex) {
} catch (WMDocumentException e) {
} catch (IOException e) {
} catch (Exception e) {
}finally{
if (xmlstream != null){
try{
xmlstream.close();
}catch (IOException e) {
}
}
}
return idataVal;
}[/highlight]