XMLstring node to idata DocumentList conversion

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]

What is the purpose of this java code? Why are you not using the built-in services pub.xml:xmlStringToNode and pub.xml:xmlNodeToDocument.

There are a number of ways to tell the xmlNodeToDocument service to identify repeating elements including populating the arrays parameter, setting makeArrays=“true” or by providing the documentTypeName with the fully qualified name of a document type which describes the repeating elements.

Mark

I hate to be cynical - but your code looks like the decompiled source for the two services Mark references above. I’m with Mark: use the services unless there is a distinctly compelling reason for writing Java code outside of the IS that directly emulates IS services.

BTW, to continue on the cynical vein: if you did decompile the two services Mark mentions, then you should have gone further to decompile com.wm.app.b2b.services.DocumentToRecordService, which likely would have answered your question.

Finally, I do NOT advocate decompiling webMethods services or server classes. (I believe the license agreement specifically states you will not.)

Hi Mark,
I apologize for not being very clear with the requirement. We are replacing one webMethods application with a java application which will generate a xml string that needs to be converted into idata and stored in the database. This needs do be done in java and outside of the webMethods environment. This idata will form as input to the webMethods application which will do further processing.
Now the issue is that certain nodes are defined as document lists in webMethods application but the function pasted below converts it into document only for single occurence and as document list for multiple occurences. We need that to be document list only reagrdless of the number of occurences.
Please see the attachment References.zip for a better picture of the requirement.
Request you to kindly respond to this as it is of utmost importance to us.
References.zip (86 KB)

Why?

Sorry, this makes no sense to me.

Makes no sense to me either. And if you really need to do some work in Java, using IData stored in a DB as the interface is probably an ill-advised approach.

To interact with Integration Server, there are several approaches that are better (better defined as less coupling with wM IS-specific data structures):

  • Write the XML string into the database directly. wM IS is certainly capable of reading that and then converting into an IS document.

  • Use HTTP post to transmit the XML string to the desired IS service.

  • Use the IS Java API to interact from your Java app to IS, though this IMO is the option of last resort.

Writing code to convert XML to IData yourself is a Very Bad Idea.

Are all the wM IS developers Java programmers? If so, you might consider the thoughts covered in this thread.