ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Parse XML from a string in a java-computenode to a value

Post new topic  Reply to topic
 Parse XML from a string in a java-computenode to a value « View previous topic :: View next topic » 
Author Message
neckh00
PostPosted: Wed Nov 14, 2007 6:47 am    Post subject: Parse XML from a string in a java-computenode to a value Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5
Location: Netherlands

Is there anyone who can help me?


From a subflow (consider this a blackbox) i have to recreate a message in a java-computenode. (It has to be a java-computenode (company-policy...))
The arriving message is containing xml-data as string in a MbElement. This MbElement has the name "bapiInfo" and is situated in the global-environment
under "/Variables/bapi/out/". The value content of this string can be something like this:
"<?xml version="1.0"?><bapiInfo xmlns="http://schemas.belastingdienst.nl/BAPI/BapiInfo/1.0.5"><messageInfo><intPID>HHHHH</intPID></messageInfo>/bapiInfo>"

What has to be done is, to retreive the value of "bapiInfo/messageInfo/intPID"

I already get lost after the toBitstream() function.


I'm new to WBIMB and java. I'm using Brokertoolkit 6.0.2 (IFIX009) on a XP machine for development.

Thanks already!

Hans


MbMessage environment = contact admin.getGlobalEnvironment();
MbElement envRoot = environment.getRootElement();

//get bapiInfo; bapiInfo is a string supplied in the global-environment in XML-format.
MbElement bapiInfoBlob = envRoot.getFirstElementByPath("/Variables/bapi/out/bapiInfo");
// bapiInfoBlob contains the info i expected at this point

//parse the content to a byte array bapiInfoByte
byte[] bapiInfoByte = bapiInfoBlob.toBitstream(null,null,MbXMLNS.PARSER_NAME, 0, 0, 0);
// HERE something goes wrong i think; bapiInfoByte seems to contain no data at all

String dummy3 = bapiInfoByte.toString();
// contains "[B@58bd0aad"; i do not recognize this content at all, neither its hex or dec. representation.

//extend the global environment with the parsed byte-array
MbElement bapiInfo = envRoot.createElementAsLastChildFromBitstream(bapiInfoByte, MbXMLNS.PARSER_NAME, null, null, null, 0, 0, 0);
bapiInfo.setName = "bapiInfo";
// there is an element with the name "bapiInfo" created in the global-environment, but it is empty

//find the ProxessID
MbElement iPID = bapiInfo.getFirstElementByPath("/bapiInfo/messageInfo/intPID");
// This gives a xml-parse exception because a part of the messagetree does not exist

//get its value
String iPIDVal = bapiInfo.getValue().toString();
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Nov 14, 2007 7:30 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

toBitstream()?

createElementAsLastChildFromBitstream?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Nov 14, 2007 2:26 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Use the SAP parser and define your tree elements. BAPIINFO is a known SAP structure... Or use the SAP adapter and access the tree...

The question really is whether your BapiInfo element has been deserialized in the Tree (or is represented as XML in your input) or whether it is just a raw block of data with the required SAP structure...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Wed Nov 14, 2007 4:59 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Okay.

So I was reading your code wrong.

The first thing is likely that Environment.Variables.bapi.out.bapiInfo has lost it's parser information.

The second is that it's a CHARACTER variable, likely, and not an XMLNS tree that can be toBitstreamed.

So you can just .getValue() on it to get a String().

Then you can extract the bytes[] from that.

Then you can call createLastElementFromBitstream() and that should parse your data.

The value from toString that you don't recognize is the default representation of what is essentially a java pointer. It's something that doesn't have a useful toString method...
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
neckh00
PostPosted: Thu Nov 15, 2007 4:15 am    Post subject: Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5
Location: Netherlands

Jeff, Thank you very much!!

It works perfectly now.
Below the code that does the job.
If you still have any comments, i will be glad to hear them.

Thanks again,

Hans




//parse bapi-info
//find bapiInfo string in the global-environment message-tree
MbElement bapiInfoBlob = envRoot.getFirstElementByPath("/Variables/bapi/out/bapiInfo");

//convert the found string to a byte array
byte[] bapiInfoByte = bapiInfoBlob.getValue().toString().getBytes();

//add the created byte array to the root of the global-environment and give it the name "parsedBapiInfo"
MbElement bapiInfoTree = envRoot.createElementAsLastChildFromBitstream(bapiInfoByte, MbXMLNSC.PARSER_NAME, null, null, null, 0, 0, 0);
bapiInfoTree.setName("ParsedBapiInfo");

//Get APDN and CPDN from bapi-info
MbElement bapiInfo = envRoot.getFirstElementByPath("/ParsedBapiInfo/bapiInfo");

String cpdn = bapiInfo.getFirstElementByPath("messageInfo/internalProcessID").getValue().toString();
String apdn = bapiInfo.getFirstElementByPath("messageInfo/externalProcessID").getValue().toString();
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Parse XML from a string in a java-computenode to a value
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.