Skip to Content

public void startElement(String namespaceURI,

          String sName, // simple name

          String qName, // qualified name

          Attributes attrs)

          throws SAXException

          {

               echoText();

               String eName = sName; // element name

               if (“”.equals(eName))eName = qName; // not namespace-aware

               if(eName.equals(“HEADER”))

                    iHeader = 1;

               if(eName.equals(“TRANSACTION”)){

                    iTrans =1;

                    sTransValue = “”;

               }

               

               if((eName.startsWith(“E_”)==true) || eName.equals(“IDOC”)==true) 

                    emitAttrs(“<“eName ” ” + attrs.getQName(0)+ “=”” + attrs.getValue(0) “”” “>”);

               else

                    emit(“<“eName“>”);

          }

This method will read the starting tag of the XML and sets the flag iHeader and iTrans whenever it reads the header and

transaction segments. I will explain the later part of this method later.

Add the following method endElement() to read the end tags of the XML document.

public void endElement(String namespaceURI,

               String sName, // simple name

               String qName  // qualified name

               )

          throws SAXException

          {

               echoText();

               String eName = sName; // element name

               if (“”.equals(eName)) eName = qName; // not namespace-aware

               if(eName.equals(“HEADER”))

                    iHeader = 0;     

               if(eName.equals(“TRANSACTION”))

                              iTrans =0;

               emit(“</”eName“>”);                         

          }

This method will read the ending tags and resets the iHeader and iTrans value again back to 0.

Add the following methods after endElements() method. (Same as that of SAX Parser)

Then comes the most important part. That is to print the document as per our needs.

1)

                         {

                              printOutPut(sMeterPntEndElementsTransEndElementsHeaderEndElement);

                              printOutPut(sHeaderValue+sTransValue);

                                   

                         }

                         iNoAsst = 0;

                         iNoRegDet = 0;

                    }

                    

                    if(s.equals(sTransStartElement))

                    {

                         iNoTrans=iNoTrans+1;

                         if(iNoRegDet>=1)printOutPut(sRegDetEndElement);

                         if(iNoAsst>=1)printOutPut(sAsstEndElement);

                         if(iNoMtPt>=1)printOutPut(sMeterPntEndElement);

                         if(iNoTrans > 1)

                         {

                              printOutPut((sTransEndElement+sHeaderEndElement));

                              printOutPut(sHeaderValue);

                         }

                         iNoMtPt = 0;

                         iNoAsst = 0;

                         iNoRegDet = 0;

                              

                    }

                    if(s.equals(sRootEndElement))

                    {

                         if(iNoRegDet>=1)printOutPut(sRegDetEndElement);

                         if(iNoAsst>=1)printOutPut(sAsstEndElement);

                         printOutPut((sMeterPntEndElementsTransEndElementsHeaderEndElement));

                         iNoTrans = 0;

                         iNoMtPt = 0;

                         iNoAsst = 0;

                         iNoRegDet = 0;

                    }     

               }

               if(s.equals(sRegDetEndElement)==false)

                    if(s.equals(sAsstEndElement)==false){

                         if(s.equals(sMeterPntEndElement)==false)

                              if(s.equals(sTransEndElement)==false)

                                   if(s.equals(sHeaderEndElement)==false)

                                   {

                                        printOutPut(s);

                                   }

                         }

          

          Echo.out.flush();

       } catch (IOException e) {

          throw new SAXException(“I/O error”, e);

       }

     }

File to Multiple IDocs (XSLT Mapping)

Hence the scenario us some thing like File->XI->BPM->IDOC. While posting from BPM to IDOC, again the XI will call the same

mapping program in interface mapping. That’s why I have added the following code in startElement() method

if((eName.startsWith(“E_”)==true) || eName.equals(“IDOC”)==true) 

                    emitAttrs(“<“eName ” ” + attrs.getQName(0)+ “=”” + attrs.getValue(0) “”” “>”);

               else

                    emit(“<“eName“>”);

“);

          nl();

     }

     public void endDocument() throws SAXException {

          try {

               nl();

               Echo.out.flush();

          } catch (IOException e) {

               throw new SAXException(“I/O error”, e);

          }

     }

public void startElement(String namespaceURI,

          String sName, // simple name

          String qName, // qualified name

          Attributes attrs)

          throws SAXException

          {

               echoText();

               String eName = sName; // element name

               if (“”.equals(eName))eName = qName; // not namespace-aware

               if(eName.equals(“HEADER”))

                    iHeader = 1;

               if(eName.equals(“TRANSACTION”)){

                    iTrans =1;

                    sTransValue = “”;

               }

               

               if((eName.startsWith(“E_”)==true) || eName.equals(“IDOC”)==true) 

                    emitAttrs(“<“eName ” ” + attrs.getQName(0)+ “=”” + attrs.getValue(0) “”” “>”);

               else

                    emit(“<“eName“>”);

          }

     public void endElement(String namespaceURI, String sName, // simple name

     String qName // qualified name

     ) throws SAXException {

          echoText();

          String eName = sName; // element name

          if (“”.equals(eName))

               eName = qName; // not namespace-aware

          if (eName.equals(“HEADER”))

               iHeader = 0;

          if (eName.equals(“TRANSACTION”))

               iTrans = 0;

          emit(“

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Michal Krawczyk
    Hi Prasad,

    nice weblog structure:
    comments, references, lots of code
    and of course the content itself 

    I enjoy reading your latest blogs 🙂

    Regards,
    michal

    (0) 
    1. Prasad Ulagappan Post author
      Michal,

      Thank you for your comments. I always get inspired by your blogs. Your blogs are always a bench mark for the weblog starters like me. 🙂

      Happy blogging,

      Regards,
      Prasad U

      (0) 

Leave a Reply