Author |
Message
|
bjr149 |
Posted: Wed Mar 03, 2010 8:52 am Post subject: Get XMLNSC Data Out Of MQ Input |
|
|
Novice
Joined: 03 Mar 2010 Posts: 22
|
Im going crazy here. Its simple. I have MQ input that reads the queue and forwards the data to my process. It is receiving data in XMLNSC.
The body variable gets "XMLNSC" when i run "body.toString()"
The message variable gets "employeelist" when i run "message.toString()"
So its as if i have the correct element. I just want to get the XML from employeelist down as a string. When I run
Code: |
List <MbElement> el = (List <MbElement>)outMessage.evaluateXPath("//XMLNSC/employeelist");
|
But when I run :
log.info("XML Data : " + Integer.toString(el.size()));
The list returns 0. It should be 1. Below is the code and the input XML that is coming in. Thanks for any help.
Quote: |
<employeelist>
<messageid>001</messageid>
<employee>
<newemployee>YES</newemployee>
<EMPNO>000500</EMPNO>
<FIRSTNAME>Robert</FIRSTNAME>
<MIDINIT>E</MIDINIT>
<LASTNAME>Crippen II</LASTNAME>
<WORKDEPT>B01</WORKDEPT>
<PHONENO>1280</PHONENO>
<HIREDATE>03/15/1999</HIREDATE>
<JOB>Worker</JOB>
<address>7 Kenicott Circle</address>
<city>Fairport</city>
<state>NY</state>
<EDLEVEL>16</EDLEVEL>
<SEX>M</SEX>
<BIRTHDATE>08/29/1958</BIRTHDATE>
</employee>
</employeelist>
|
Code: |
MbMessage inMessage = contact admin.getMessage();
outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,outMessage);
MbElement root = contact admin.getMessage().getRootElement();
MbElement body = root.getLastChild(); //gives XMLNSC
MbElement message = body.getFirstChild(); //gives message
log.info("body : " + body.toString());
log.info("body : " + body.getValueAsString());
log.info("message : " + message.toString());
log.info("message : " + message.getValueAsString());
List <MbElement> el = (List <MbElement>)outMessage.evaluateXPath("//XMLNSC/employeelist");
log.info("XML Data : " + Integer.toString(el.size()));
|
|
|
Back to top |
|
 |
mqjeff |
Posted: Wed Mar 03, 2010 12:18 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You no longer have any XML content by the time you get to your plugin node.
You only have a Message Tree consisting of MBElements. |
|
Back to top |
|
 |
bjr149 |
Posted: Wed Mar 03, 2010 12:34 pm Post subject: |
|
|
Novice
Joined: 03 Mar 2010 Posts: 22
|
IM using this code in java compute node. The issue was that the correct XPath to use was
Code: |
List <MbElement> el = (List <MbElement>)outMessage.evaluateXPath("/employeelist/employee");
|
I didnt need the XMLNSC.
NOw im on to a new issue. Below is the code i use on the InMessage to just get the entire XML content. It works great and prints out the message in the log.
Code: |
byte [] msgAsBytes = inMessage.getRootElement().getLastChild().toBitstream(null,null,null,0,0,0);
String msgAsText = new String(msgAsBytes);
log.info("msgAsText :"+ msgAsText.toString());
|
THe problem is I later loop over the list of the 2 employees using a for each .
Code: |
List <MbElement> el = (List <MbElement>)outMessage.evaluateXPath("/employeelist/employee");
log.info("XML Employee List Count : " + Integer.toString(el.size()));
for (MbElement element : el)
{
log.info("Name :"+ element.getName());
log.info("1");
byte[] bs = element.toBitstream(null,null,null,0,1208,0);
log.info("2");
String mbXML = new String(bs, "UTF-8");
log.info("3");
log.info("new byte stream :"+ Integer.toString(mbXML.length()));
log.info("msg :"+ mbXML.toString());
}
|
When I try to run the toBitstream on the MbElement and not the MbMessage I get an error.
Quote: |
<com.ibm.broker.plugin.MbParserException class:JNI method:ImbXMLNSCParser::refreshBitStreamFromElementsCommon source:BIPv610 key:5010 >
|
When I lookup the error I get.
Quote: |
5010: BIP5010E: \
XML Writing Errors have occurred. \n\nErrors have occurred during writing of XML. \n\nReview further error messages for an indication to the cause of the errors.
|
I have no idea what to do now. I didn't do anything to the xml and I get the error. Its like I have to do an encoding or something. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Mar 03, 2010 12:36 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If you were using the ESQL ASBITSTREAM function to conver a message tree into a stream of bytes, you would have to use the FolderBitStream constant with the ASBITSTREAM function to indicate that you wanted to work with a partial tree instead of a full message. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Mar 04, 2010 12:30 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I'm confused.
Quote: |
I have MQ input that reads the queue and forwards the data to my process. It is receiving data in XMLNSC |
This crops up all the time. If you are simply forwarding the data without changing it, then you don't need to parse it and then re-serialize it. Just change the MQInput node domain to 'BLOB' and forward the bytes to your other process.
If you need to parse the BLOB in the main flow, you can do that using MbElement.createElementAsLastChildFromBitstream().
Quote: |
When I lookup the error I get.
Quote:
5010: BIP5010E: \
XML Writing Errors have occurred. \n\nErrors have occurred during writing of XML. \n\nReview further error messages for an indication to the cause of the errors.
I have no idea what to do now |
Well...the error message had a good suggestion. Have you tried it?  |
|
Back to top |
|
 |
bjr149 |
Posted: Thu Mar 04, 2010 5:35 am Post subject: |
|
|
Novice
Joined: 03 Mar 2010 Posts: 22
|
I guess my posting was a little confusing. Im more or less doing research how to accomplish the same this in a JavaCompute node that we could accomplish using eSQL. My architect wants someone to do some research and I was chosen. I would like to use the "Mb" classes to just travese through an XML document just to see if we could use the data as a lookup or just do some calculations. Like I said this is more of a research thing. I figured out how to traverse through the document and get the data that is only 1 level deep. Still though as a MbElement I can't just get the string XML string out of it because of that XML writing error. Are there any places that I can see a more descriptive error? I did read the error and it doesn't tell me much. I can export the MbMessage with no problems toBitStream ok and see the entire XML coming in. If I try the toBitStream on the MbElement is where it throws the error. Im just seeing what kind of options we have. I don't want to have to go old school with java XML Parsing classes. I would like to try the built in ones.
The code I have now works good by running through the inbound XML employee record by record printing out the values. The only issue is getting the XML string out of the MbElements. Again this is just research and Im trying to see all of my options.
Code: |
MbElement root = contact admin.getMessage().getRootElement();
MbElement body = root.getLastChild(); //gives XMLNSC
MbElement message = body.getFirstChild(); //gives message
log.info("body : " + body.getName());
log.info("message : " + message.getName());
byte [] msgAsBytes = inMessage.getRootElement().getLastChild().toBitstream(null,null,null,0,0,0);
String msgAsText = new String(msgAsBytes);
log.info("msgAsText :"+ msgAsText.toString());
List <MbElement> el = (List <MbElement>)outMessage.evaluateXPath("/employeelist/employee");
log.info("XML Employee List Count : " + Integer.toString(el.size()));
log.info("a");
for (MbElement element : el)
{
MbElement Child1 = element.getFirstChild();
if(Child1 != null)
{
int x = 1;
while(Child1 != null)
{
log.info("Child1 (sibling tag " + Integer.toString(x) + ") = " + Child1.getName());
log.info("Child1 (sibling value " + Integer.toString(x) + ") = " + Child1.getValueAsString());
x++;
Child1 = Child1.getNextSibling();
}
}
|
|
|
Back to top |
|
 |
kimbert |
Posted: Thu Mar 04, 2010 6:10 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I would like to use the "Mb" classes to just travese through an XML document just to see if we could use the data as a lookup or just do some calculations. |
That should be possible. There are a few advanced things that ESQL can do and JavaCompute node cannot do, but traversing the tree and getting the logical values of the elements should be trivial.
Quote: |
Still though as a MbElement I can't just get the string XML string out of it because of that XML writing error. |
Big question: why do you want the XML string in your message flow. The whole point of message broker is that the message flow deals with the logical content of the data, and it does not know or care what the original physical format was. I think you're confused. You should be trying to get the value ( not the original XML string value ) of the element. I could tell you how to do that, but the infocenter page for MbElement should tell you easily enough.
Quote: |
Are there any places that I can see a more descriptive error? |
Where do you normally look for errors which your message flows emit? Have you looked in those places?
Quote: |
I did read the error and it doesn't tell me much. |
It did not claim to tell you very much, but it did tell you to 'Review further error messages for an indication to the cause of the errors. '
Quote: |
Im just seeing what kind of options we have. I don't want to have to go old school with java XML Parsing classes. I would like to try the built in ones. |
You should start by understanding how message broker is supposed to be used. Otherwise, you're going to explore the wrong set of options. You are right about not using Java XML classes, though. That would be *really* silly, given that you've bought message broker. |
|
Back to top |
|
 |
bjr149 |
Posted: Thu Mar 04, 2010 6:29 am Post subject: |
|
|
Novice
Joined: 03 Mar 2010 Posts: 22
|
Thanks for the posts. I see for your responses about not using Message Broker for the wrong thing as a statement that you must not work for big companies.
It is simple... They buy a tool and you make it work for anything they want. I know Message Broker is not going to be used correctly but that is not my choice. If it was my choice we would have the process server with the Integration Developer and the Message Broker, but I am a middle level fish, with zero clout.
For now I am just exploring the capabilities and the tools available within the message broker to do "Integration". |
|
Back to top |
|
 |
|