Hi Chandru,

I haven't stayed completely current on the latest changes, but AFAIK you're not going to get what you want by using AXIOM. By design, AXIOM will hold on to the constructed elements as you move through the list, so that you'll end up building the entire list in memory.

To process this type of structure without building it in memory you need to either work directly with the parser or use a data binding implementation that allows you to process documents one piece at a time. You can do this with JiBX, for instance, by writing a custom unmarshaller for the <batch-request> element which just unmarshals and processes each <addRequest> separately, without holding on to the ones that have already been processed. I think you can use similar approaches with JAXB.

 - Dennis

--
Dennis M. Sosnoski
SOA and Web Services in Java
Axis2 Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117


Ganesan, Chandru wrote:
Hi

Is there any AXIOM expert in this group who can answer this question?

I sent this question to the appropriate group "[EMAIL PROTECTED]", 
unfortunately this group is not quite active as I've not been getting any emails from 
this group for past few days.

Thanks
Chandru Ganesan
-----Original Message-----
From: Ganesan, Chandru
Sent: Tuesday, December 18, 2007 5:13 PM
To: [email protected]
Subject: StAX parsing of XML file using AXIOM API

Hi

I'm a newbie to Apache Axis2. I have few questions on AXIOM (StAX)API. Since I 
didn't get any answers to my original post to '[EMAIL PROTECTED]' mailing list, 
 I'm posting to this group hoping for answers/guidance.

I'd like to parse a huge file without building complete object model (linked 
list of OM elements) in memory i.e., I don't want the effect of going back in 
the inputstream and reading elements.

I have following file structure:

<Soap-Envelope>
  <Soap-Header>
    ....
  </Soap-Header>

  <Soap-Body>
    <batch-request>
      <addRequest>
         ......
      </addRequest>

      <addRequest>
           <!--  thousands of addRequests here. I'd like to parse each addRequest 
one at a time without preserving OM elements of previous and subsequent elements  >
      <addRequest>

    </batch-request>
  </Soap-Body>
</Soap-Envelope>

I have following questions:

1. During my analysis, I found out that whenever I use an Iterator, as in the 
code snippet below, to get a childElement using iterator.next(), AXIOM builds a 
link list of all child elements  (OM Element) similar to DOM tree i.e., whole 
document is parsed and OM elements are created in memory.

.....
QName qName = new QName("http://schemas.xmlsoap.org/soap/envelope";, "Body", 
"soap"); Iterator itr = soapEnvelope.getChildrenWithName(qName);
while(itr.hasNext()) {
   OMElement element = (OMElement) itr.next(); }

However, when I used StAXSOAPModelBuilder to extract SOAPEnvelope, SOAPElement, 
SOAPBody it is able to build without parsing the whole file. Following code 
does not build complete object model:

 StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser, 
"http://schemas.xmlsoap.org/soap/envelope/";);
            QName soapHeaderQName = new 
QName("http://schemas.xmlsoap.org/soap/envelope/";, "Header");
            SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
            SOAPHeader soapHeader = envelope.getHeader();

            QName soapBodyQName = new QName("http://schemas.xmlsoap.org/soap/envelope/";, 
"Body");
            SOAPBody soapBody = envelope.getBody();
            OMElement elem = soapBody.getFirstElement();


2. What is the best way to parse above SOAP file one addRequest at a time 
without building OM elements for previous/subsequent addRequests? I cannot use 
SOAP builder as I have some XML files which are not SOAP based.

Chandru Ganesan
HP Select Identity
972.497.2403 (Work)
3000 Waterview Pkwy
Richardson TX 75080


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to