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 » Problem in accessing Namespace in Java.

Post new topic  Reply to topic
 Problem in accessing Namespace in Java. « View previous topic :: View next topic » 
Author Message
OMG
PostPosted: Tue Aug 07, 2012 4:21 am    Post subject: Problem in accessing Namespace in Java. Reply with quote

Novice

Joined: 20 Feb 2012
Posts: 18

I have a XML message as below:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Log xmlns:BMW="BMW-EXTENSIONS" xmlns:ace="Lookup table for taxes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.nrf-aprts.org/IXRetail/namespace/" xsi:schemaLocation="http://www.nrf-arts.org/IXRetail/namespace/ BMWPOSLog.xsd">
 <Transaction Flag="false">
  <StoreID>333</StoreID>
  <DrawerNo>1</DrawerNo>
  <ImmediateTransaction Version="2.1">
   <FailureCode/>
   <BMW:SignOff xsi:type="BMW:SimpleImmediateTransaction" xsi:schemaLocation="BMW-EXTENSIONS BMWLogImmediateTransaction.xsd">
    <BMW:DateTimestamp>2010-12-08 06:45:00</BMW:DateTimestamp>
    <BMW:Header>
     <BMW:GroceryHeader>
      <BMW:GroceryTerminal>0077</BMW:GroceryTerminal>
      <BMW:GroceryTransactionNumber>0270</BMW:GroceryTransactionNumber>
      <BMW:GroceryDateTime>2010-12-08 06:45:00</BMW:GroceryDateTime>
    </BMW:GroceryHeader>
   </BMW:Header>
   </BMW:SignOff>
   <SignOff>
    <SessionSettle>
     <TenderSummary>
      <Loan>
       <Amount>0.00</Amount>
       <Count>0</Count>
      </Loan>
      <Pickup>
       <Amount>0.00</Amount>
       <Count>0</Count>
      </Pickup>
     </TenderSummary>
    </SessionSettle>
   </SignOff>
  </ImmediateTransaction>
 </Transaction>
</Log>


I have to access the elements in first instance of "SignOff" with 'BMW' namespace (like GroceryTerminal,GroceryTransactionNumber etc) . The ESQL code for this is (The value has been accessed in str0hdr variable.):


Code:
DECLARE ns NAMESPACE 'http://www.nrf-aprts.org/IXRetail/namespace/' (http://www.nrf-aprts.org/IXRetail/namespace/%27);
DECLARE bmw NAMESPACE 'BMW-EXTENSIONS';

DECLARE reftr REFERENCE TO InputRoot.XMLNSC.ns:Log.ns:Transaction;
DECLARE refImmediateTransaction REFERENCE TO reftr.ns:ImmediateTransaction;
SET str0hdr = refImmediateTransaction.bmw:*[1].bmw:Header.bmw:GroceryTerminal;


Can any body please let me know what should be the equivalent java code for the above segment??

In the Java Compute Node, If I directly try to access the value without considering the name space, then I can get something (which is not correct):

Code:
MbElement string20Header = inputBody.getFirstElementByPath("./Log/Transaction/ImmediateTransaction/SignOff/Header/GroceryTerminal");
String stre =  string20Header.getValueAsString();


But here, logically , I am not getting the desired result as I need the first occurence of "SignOff" with 'BMW' namespace --- Which is correctly coded in ESQL. SO I need assistance to formulate that Java code to that ESQL into Perfect Java.

Thanks in advance.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Aug 07, 2012 5:14 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

You should consider Using Xpath.

Note also that MBElement has a namespace attribute as well.
Back to top
View user's profile Send private message
mattfarney
PostPosted: Wed Aug 08, 2012 3:20 pm    Post subject: Reply with quote

Disciple

Joined: 17 Jan 2006
Posts: 167
Location: Ohio

I don't have the ability to test either of these, but did you try the full path?

Code:
("./Log/Transaction/ImmediateTransaction/BMW:SignOff/BMW:Header/BMW:GroceryTerminal");

or more explicitly
Code:
("./Log/Transaction/ImmediateTransaction/BMW-EXTENSIONS:SignOff/BMW-EXTENSIONS:Header/BMW-EXTENSIONS:GroceryTerminal");


-mf
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 » Problem in accessing Namespace in Java.
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.