SAX-parser and mapping on the XI

Helllo everybody,
I'm trying to map an xml-document using the SAX-parser.
I'm reading the data using an impustream. the problem is, while testing on the XI, the following message comes :
Creating Java mapping xmlDataExchangeSAPSample/XMLValidation
Loaded class xmlDataExchangeSAPSample.XMLValidation
Loaded class xmlDataExchangeSAPSample.myErrorHandler
Call method execute of the application Java mapping xmlDataExchangeSAPSample.XMLValidation
START APPLICATION TRACE ***
xxx implementierende Klasse Parserscom.sap.engine.lib.jaxp.SAXParserFactoryImpl
erstelltes Dokument aus in EDIFACTINTERCHANGE
Beginn Parsenjava.io.ByteArrayInputStream@1aa342a3
SAXException when parsing Generic Exception:
com.sap.engine.lib.xml.util.NestedException -> com.sap.engine.lib.xml.parser.ParserException -> java.io.IOException: Parsing an empty source. Root element expected!
END APPLICATION TRACE ***
Java mapping xmlDataExchangeSAPSample/XMLValidation completed. (execute() of xmlDataExchangeSAPSample.XMLValidation
Ausführung war erfolgreich.
10:18:14 Testende
the the Document ist generated :
"...erstelltes Dokument aus in EDIFACTINTERCHANGE.."
but the parser find an empty source.
do you have an idea what could be happening here?
Kind regards

Hi,
  <<
xxx implementierende Klasse Parserscom.sap.engine.lib.jaxp.SAXParserFactoryImpl
erstelltes Dokument aus in EDIFACTINTERCHANGE
Beginn Parsenjava.io.ByteArrayInputStream@1aa342a3
SAXException when parsing Generic Exception:
com.sap.engine.lib.xml.util.NestedException -> com.sap.engine.lib.xml.parser.ParserException -> java.io.IOException: Parsing an empty source. Root element expected!
>>
This seems that u r trying parse a file rather than valid XML document..
Usually you will notice this problem when u r trying to parse a payload which is in txt format usually when u r using File Adapter message protocol as "FILE" instead of "FCC".
Usually SAX is an API Desinged to parse Valid XML Documents only.
If you want to do manipulations on NON XML data better to use Java.io.InputStream & OutputStream.
Regards,
Rao.Mallikarjuna

Similar Messages

  • SAX Parser and special character problem

    Hi,
    Could anyone help with the following problem?
    Background:
    1. Using a SAX Parser (Oracle Implementation) to read XML from a CLOB, convert this XML to another format to be inserted in the database.
    2. Due to performance issues we parse the input stream from the CLOB.
    3. For same reason, we are not using XSL.
    This is the problem we face:
    1. Values of some of the tags in the XML have special characters (Ex: &, <, >).
    2. While using the SAX Parser, the element handler function for the SAX Parser is called by the frame work with the value of these tags broken up with each of these characters being treated as a tag delimiter.
    Ex: <Description>SomeText_A & SomeText_B</Description>
    is treated as SomeText_A in first call to the handler; SomeText_B in the second call.
    The handler function does not get to see the "&" character.
    Thus, the final conversion is
    Say, <Description> is to be converted to <FreeText>
    we, get <FreeText>SomeText_A</FreeText>
    <FreeText>SomeText_B</FreeText>
    We tried using &; but it then breaks it up into SomeText_A, & and SomeText_B.
    How can we get the whole value for the <Description> tag in the characters() function in the SAXParser so that we can convert it to <FreeText>SomeText_A & SomeText_B</FreeText>.
    Thanks in advance..
    Chirdeep.

    We already tried that..looks like the line where I mentioned that it converted the entity referece characters to an ampersand..
    "We tried using <entity reference for &> but it then breaks it up into SomeText_A, & and SomeText_B."
    null

  • SAX parsing and loops problem

    Hi!
    I currently have an XML file which looks like this:
    <jel>
    <admin creation="Fri Nov 09 17:14:55 GMT 2007" xsdversion="1.0.0" version="1.0.0"/>
    &#8722;
         <jelclass superclass="Object" visibility="public" package="" superclassfulltype="java.lang.Object" fulltype="Player" type="Player">
    &#8722;
         <implements>
    <interface fulltype="java.awt.event.ActionListener" type="ActionListener"/>
    <interface fulltype="java.awt.event.KeyListener" type="KeyListener"/>
    </implements>
    &#8722;
         <methods>
    &#8722;
         <constructor visibility="public" name="Player">
    &#8722;
         <params>
    <param name="newProtocol" fulltype="NewProtocol" type="NewProtocol"/>
    <param name="x" fulltype="int" type="int"/>
    <param name="y" fulltype="int" type="int"/>
    </params>
    </constructor>
    &#8722;
         <method visibility="public" name="actionPerformed" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.ActionEvent" type="ActionEvent"/>
    </params>
    </method>
    &#8722;
         <method visibility="public" name="keyPressed" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.KeyEvent" type="KeyEvent"/>
    </params>
    </method>
    &#8722;
         <method visibility="public" name="keyReleased" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.KeyEvent" type="KeyEvent"/>
    </params>
    </method>
    &#8722;
         <method visibility="public" name="keyTyped" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="e" fulltype="java.awt.event.KeyEvent" type="KeyEvent"/>
    </params>
    </method>
    <method visibility="public" name="getX" fulltype="int" type="int"/>
    &#8722;
         <method visibility="public" name="setX" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="x" fulltype="int" type="int"/>
    </params>
    </method>
    <method visibility="public" name="getY" fulltype="int" type="int"/>
    &#8722;
         <method visibility="public" name="setY" fulltype="void" type="void">
    &#8722;
         <params>
    <param name="y" fulltype="int" type="int"/>
    </params>
    </method>
    </methods>
    </jelclass>And I have SAX parsing code that looks like this:
    public class SaxParser{
          private HashSet <String>packageSet = new HashSet<String>();
          private ArrayList <String> classList = new ArrayList<String>();
          private ArrayList <String> packageList = new ArrayList<String>();
          private ArrayList <String> methodList = new ArrayList<String>();
          private Object[] packageNames;
          private HashMap <String, ArrayList> h = new HashMap <String, ArrayList>();
          public SaxParser()throws Exception{
              String fname = "eclipse/jel.xml";
             DefaultHandler handler = new DefaultHandler()
                 private int numberOfClasses = 0;
             public void startElement(String namespaceURI,String localName, String qname, Attributes attrs)
                  if(qname.equals("jelclass")) {
                       numberOfClasses ++;
                  for(int i = 0; i< attrs.getLength();i++){
                        if(attrs.getQName(i).equals("type")){
                             classList.add(attrs.getValue(i));
                             if(attrs.getQName(i).equals("package")){
                                  packageList.add(attrs.getValue(i));
                                  packageSet.add(attrs.getValue(i));
                  for(int i = 0; i< attrs.getLength();i++){
                       for(int j = 0; j < classList.size(); j++){
              if(attrs.getQName(i).equals("type") && attrs.getValue(i).equals(classList.get(j))){
                  if(qname.equals("method")){
                        if(attrs.getQName(i).equals("name")){
                                    h.put(classList.get(i), methodList.add(attrs.getValue(i));
                   packageNames = new String[packageSet.size()];
                  packageNames = packageSet.toArray();
             public void endElement(String namespaceURI,String localName, String qname){}};
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(new File(fname), handler);
         public int getPackageNumber(){
              return packageSet.size();
         public Object[] getPackageNames(){
              return packageNames;
         public ArrayList getPackageList(){
              return packageList;
         public ArrayList getClassList(){
              return classList;
         public ArrayList getMethodList(){
              return methodList;
          public static void main(String[] args)throws Exception{
               new SaxParser();
    }I am currently pulling out the package names, pulling out the classnames and then mapping these in a separate class - this works because the class and package names are declared in the same line, so if a package name appears in the package list 7 times, i know this package has 7 classes, and therefore i count the first 7 classes out of an array of all the classes and know that these are the right 7 for that package. However, the methods are a bit different:
    What I would like to do is to: for every class make a hashmap which maps the class name onto an arraylist of the methods, but i think i'm getting confused with my for loops. Or even just keep a tally of how many methods each class has, then I can work it out as i did with the packages -> classes.
    Does anyone know where im going wrong, or have any ideas at all?
    Thank you for your time,
    beccy
    :)

    I don't know if stacks are specifically mentioned in any SAX documentation.
    Basically, SAX sends you a stream of XML elements (open and close tags, characters, etc.), but it doesn't know anything about the underlying XML structure. You have to add that part (usually -- sometimes when writing a SAX application, you don't really care about the XML structure). XML structure is a tree.
    If you've ever written a recursive function that spans a tree, you'll have an idea what to do. You can use a stack to keep track of where you are in the tree. For example, if you open tag A, then you're "in" the A element for subsequent content in that document; if you then open tag B, you're in the B element; but when you close the B tag, you need the stack to tell you that now you're back in the A element.
    You may not need stacks, but it's likely. Find a good tutorial about SAX that mentions stacks and you'll be fine.
    Edited by: paulcw on Nov 14, 2007 4:09 PM

  • SAX parser and EntityResolver

    I am using the sample SAXSample.java that comes as part of the XML parser download to parse an XML file that contains references to external entities - for example <!ENTITY E23678 SYSTEM "http://pilot/:13365">
    However the SAX parser never appears to call either the EntityResolver or DTDHandler handlers even though they are set in main.
    Has anyone else experienced this or have a missed something out?
    Any help appreciated.

    public class YourParser extends DefaultHandler implements Runnable
    in yor run method
    saxParser.parse(fileToBeParsed, this); provide implementation to the methods y want in YourParser  class
    //saxParser is an object of javax.xml.parsers.SAXParser

  • RAP and MAPs change the channel and Radio Role

    I have a WLC 2504 with version  AIR-CT2500-K9-7-5-102-0, LAPs are AIR-CAP2602E-A-K9
    I set serveral LAPs for working in mesh mode, I set three Bridge Group Name, the first group has one Root AP and three MAPS working in channel 157, every MAP has a switch connected to its ethernet port.
    the second group has 2 LAPs one Root and one MAP, all working in channel 48. The MAP  is connected to a switch.
    the third group has  2 LAPs, one root and one MAP, all working in channel 149. The MAP  is connected to a switch.
    The issue is the next:
    At the beginnig every LAPs were associated to its bridge group and in the channel defined but suddenly all LAPs of group 1 move to channel 48 (second group) includind the ROOT AP. This happend after the switch that connect to the RAP was disconnect from  LAN.
    In order the associate once again LAPs of the first group  to the channel I defined previously I connected RAP to the switch once again I notice the channel shown was 48 and in downlink role mode.I change to channel 157 reset the LAP and wait several minutes; after the first reset the RAP remains in channel
    48 (it must be 157), I reset once again and wait severeal minutes. Finally the RAP was up and working in channel 157.
    After this I reset the MAPs that corresponde to BGN 1 , after severasl minutes finally just one MAPs for BGN 1 was show in the correct channel and in the correct Radio role, I have to reset several times  the other MAPs until they were shown in the channel I set previously and in the correct radio role.
    I would like to know the reason the RAP and MAP move to a differente channel eventhough I define de Bridge Group Name in every one and the specific channel.
    regards

    Hi scott ,
    Thanks for your explanation, very clear.
    In my scenario  every RAP connet to a switch where I define VLANs and specific VLANs are allow to pass. If RAP and MAP join to a different RAP (different BGN)
    it will allow to pass traffic or maybe don't allow traffic I needs to .  That's why I worry about the keep the MAPs join to the correct RAP and the RAP keep in the BGN and channel set previously.
    is there any option to this  avoid this issue?
    Thanks a lot for your time
    regards

  • Multiple columns (named the same originally) and mapped to the same lookup table are causing a Cube Build issue

    Hey folks, looking for some insight here.
    I've an implementation that contains some custom Enterprise columns mapped to lookup tables.  In the instance I'm working with now, it looks like there was/is an issue with one of those columns.  In this scenario, I have a column named
    ProjectType, created initially with that name, mapped to a lookup table.  This field's name was then changed to
    Project Type.  After that, it looks like another column was created, also called
    ProjectType.  So now, we have what I would have originally thought was two distinct columns, even though the names used are the same.
    Below is the error we're currently getting during the Cube Build Process...
    PWA:http://ps2010/PWA, ServiceApp:Project Web App, User:DOMAIN\user, PSI: SqlException occurred in DAL:  <Error><Class>1</Class><LineNumber>1</LineNumber><Number>4506</Number><Procedure>MSP_EpmProject_OlapView_B8546719-4D4C-473A-84B1-89DEDA2307E0</Procedure> 
    <Message>  System.Data.SqlClient.SqlError: Column names in each view or function must be unique. Column name 'ProjectType' in view or function 'MSP_EpmProject_OlapView_B8546719-4D4C-473A-84B1-89DEDA2307E0' is specified more than once.  </Message> 
    <CallStack>   
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)   
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)   
     at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)   
     at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)   
     at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)   
     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)   
     at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)   
     at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()   
     at Microsoft.Office.Project.Server.DataAccessLayer.DAL.SubDal.ExecuteStoredProcedureNoResult(String storedProcedureName, SqlParameter[] parameters)  </CallStack>  </Error>
    I've tried deleting the one column, but the build still gives the above error.
    Any thoughts as to how the above could be resolved?
    Thanks! - M
    Michael Mukalian | Jan 2010 - Dec 2010 MVP SharePoint Services | MCTS: MOSS 2007 Configuration | http://www.mukalian.com/blog

    We tried taking it out of the cubes, and it builds fine.  The challenge we're having is in building the cubes with that custom field "ProjectType".  It's as if the cubes still hold some reference to it even when it's deleted.
    Since the OLAP View ('MSP_EpmProject_OlapView_{guid}') is recreated, would it be as simple as deleting that View, and trying to recreate?
    Thanks - M
    Michael Mukalian | Jan 2010 - Dec 2010 MVP SharePoint Services | MCTS: MOSS 2007 Configuration | http://www.mukalian.com/blog

  • Using the SAX Parser

    As I reported in this thread: Carriage Returns in XSLT output I am trying to produce a text output file with each line terminating in cr-lf (using the output from ViewObject.writeXML() passed through the XSLProcessor.processXSL() method to apply a XSLT stylesheet transformation to it), but the cr characters in the stylesheet are being converted to nl characters, so I am ending up with two nl characters at the end of each line.
    I found a 2002 query (here: http://www.xslt.com/html/xsl-list/2002-04/msg00193.html) by someone with the same problem, and a reply by Steve Muench explaining it and stating that the Oracle SAX parser does not have the same problem.
    So my question now is - does the SAX parser still retain cr characters (or is it too now converting them to nl) and if it does, how do I make XSLProcessor.processXSL() use it rather than the default XML parser? Can I do it from within my code, or does it need to be set in some sort of environment variable? We are on version 9.0.5.2 of JDeveloper(10g)

    Repost

  • Java SAX parser. How to get raw XML code of the currently parsing event?

    Java SAX parser, please need a clue how to get the raw XML code of the currently parsing event... needed for logging, debugging purposes.
    Here's and example, letting me clarify exactly what i need: (see the comments in source)
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
         //..Here... or maybe somewhere elsewhere I need on my disposal the raw XML code of
         //..every XML tags received from the XML stream. I need simply to write it down
         //..in a log file, for debugging purposes, while parsing. Can anyone give me a suggestion
         //..how can i implement such logging while the SAX parser only returns me the tagname and
         //..attributes. While parsing I want to log the XML code for every tag in
         //..its 'pure form', like it is comming from the server directly on the
         //..socket's input reader.
         if ("p".equals(qName)) {
              etc...
    }Than you in advance.

    YES!
    I've solved my problem using class RecordingInputStream that wraps the InputStream
    here is the class source code:
    import java.io.ByteArrayOutputStream;
    import java.io.FilterInputStream;
    import java.io.InputStream;
    import java.io.IOException;
    * @author Unknown
    class RecordingInputStream  extends  FilterInputStream {
         protected ByteArrayOutputStream sink;
        RecordingInputStream(InputStream in) {
            this(in, new ByteArrayOutputStream());
        RecordingInputStream(InputStream in, ByteArrayOutputStream sink) {
            super(in);
            this.sink = sink;
        public synchronized int read() throws IOException {
            int i = in.read();
            sink.write(i);
            return i;
        public synchronized int read(byte[] buf, int off, int len) throws IOException {
            int l = in.read(buf, off, len);
            sink.write(buf, off, l);
            return l;
        public synchronized int read(byte[] buf) throws IOException {
            return read(buf, 0, buf.length);
        public synchronized long skip(long len) throws IOException {
            long l = 0;
            int i = 0;
            byte[] buf = new byte[1024];
            while (l < len) {
                i = read(buf, 0, (int)Math.min((long)buf.length, len - l));
                if (i == -1) break;
                l += i;
            return l;
        byte[] getBytes() {
            return sink.toByteArray();
        void resetSink() {
            sink.reset();
    } Then here is the initialization before use with SAX:
    this.psock = new Socket(this.profile.httpServer, Integer.parseInt(this.profile.httpPort));
    this.out = new PrintWriter(this.psock.getOutputStream(), true);
    this.ris=new RecordingInputStream(this.psock.getInputStream());
    this.in=new BufferedReader(new InputStreamReader(this.ris));
    try {
         this.parser = SAXParserFactory.newInstance().newSAXParser();
         this.parser.parse(new InputSource(this.in),new XMLCommandsHandler());
    catch (IOException ioex) {  }
    catch (Exception ex) {  }Then the handler class looks like this (it will be an inner class, so you can access ris, from the parent class):
    class XMLCommandsHandler extends DefaultHandler {
         public void startDocument() throws SAXException {
              //...nothing
         public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
              // BEGIN - Synchronized logging of raw XML source code in parallel with SAX parsing :)
              byte[] bs=ris.getBytes();
              logger.warn(new String(bs));
              ris.resetSink();
              // End logging
              if ("expectedTagThatTriggersMeToDoSomething".equals(qName)) {
                   //...Do smth.
    }Edited by: patladj on Jul 3, 2008 12:30 PM

  • JDBC receiver adapter - Error processing request in sax parser

    Hello,
    I want to INSERT idoc data via JDBC adapter into a MS SQL database. After digging through SAP Help, numerous blogs and forum discussions on SDN and even posting an OSS message I still get the same error:
    'Error: TransformException error in xml processor class: Error processing request in sax parser: No 'action' attribute found in XML document (attribute "action" missing or wrong XML structure)'
    When testing my mapping in the Integration Repository the resulting XML message is:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Employee xmlns:ns0="http://prodrive.nl/xi/HRMasterdata/HRMD_A_2_d_bcommerp">
       <STATEMENT>
          <T_PD_Employees action="INSERT">
             <access>
                <KeyTag>00088888</KeyTag>
                <PerNo>00088888</PerNo>
             </access>
          </T_PD_Employees>
       </STATEMENT>
    </ns0:Employee>
    The connection to the database is fine, Sender adapter with a SELECT * works perfect.
    Can anyone help me solve this problem? I'm lost.
    Best regards,
    Roelof Jan Bouwknegt

    Hi Bhavesh,
    I have tried out the change you suggested. Without success. Message I get back is
    - 2006-12-28 10:34:08 CET: Error: TransformException error in xml processor class: Error processing request in sax parser: No 'action' attribute found in XML document (attribute "action" missing or wrong XML structure)
    structure in testtool:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Employee xmlns:ns0="http://prodrive.nl/xi/HRMasterdata/HRMD_A_2_d_bcommerp">
       <STATEMENT>
          <T_PD_Employees action="INSERT">
             <ACCESS>
                <KEYTAG>00088888</KEYTAG>
                <PERNO>00088888</PERNO>
             </ACCESS>
          </T_PD_Employees>
       </STATEMENT>
    </ns0:Employee>
    Somehow the SAX  parser doesn't like the result of my mapping. Maybe there is something wrong with the structure cardinality. Let me describe what I have built:
    XSD:
    WA_T_PD_Employees - Complex Type
    > STATEMENT - Element - Occurence = 1
    >> T_PD_Employees - Element - Occurence = 1
    >>> STATEMENT - Attribute - Occurence = optional
    >>> access - Element - Occurence = 1..Unbounded
    Best regards Roelof Jan and thanks for your quick response

  • How to deal with empty tags in a SAX Parser

    Hi,
    I hope someone can help me with the problem I am having!
    Basically, I have written an xml-editor application. When an XML file is selected, I parse the file with a SAX parser and save the start and end locations of all the tags and character data. This enables me to display the xml file with the tags all nicely formatted with pretty colours. Truly it is a Joy To Behold. However, I have a problem with tags in this form:
    <package name="boo"/>
    because the SAX parser treats them like this:
    <package name = boo>
    </package>
    for various complex reasons the latter is unaccetable so my question is: Is there some fiendishly clever method to detect tags of this type as they occur, so that I can treat them accordingly?
    Thanks,
    Chris

    I have spent some time on googling for code doing this, but found nothing better, than I had to write in by myself.
    So, it would be something like this. Enjoy :)
    package comd;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.SAXException;
    import org.xml.sax.Attributes;
    import java.util.Stack;
    import java.util.Enumeration;
    public class EmptyTagsHandler extends DefaultHandler {
         private StringBuilder xmlBuilder;
         private Stack<XmlElement> elementStack;
         private String processedXml;
         private class XmlElement{
              private String name;
              private boolean isEmpty = true;
              public XmlElement(String name) {
                   this.name = name;
              public void setNotEmpty(){
                   isEmpty = false;
         public EmptyTagsHandler(){
              xmlBuilder = new StringBuilder();
              elementStack = new Stack();
         private String getElementXPath(){
              StringBuilder builder = new StringBuilder();
              for (Enumeration en=elementStack.elements();en.hasMoreElements();){
                   builder.append(en.nextElement());
                   builder.append("/");
              return builder.toString();
         public String getXml(){
              return processedXml;
         public void startDocument() throws SAXException {
              xmlBuilder = new StringBuilder();
              elementStack.clear();
              processedXml = null;
         public void endDocument() throws SAXException {
              processedXml = xmlBuilder.toString();
         public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
              if (!elementStack.empty()) {
                   XmlElement elem = elementStack.peek();
                   elem.setNotEmpty();
              xmlBuilder.append("<");
              xmlBuilder.append(qName);
              for (int i=0; i<attributes.getLength();i++){
                   xmlBuilder.append(" ");
                   xmlBuilder.append(attributes.getQName(i));
                   xmlBuilder.append("=");
                   xmlBuilder.append(attributes.getValue(i));
              xmlBuilder.append(">");
              elementStack.push(new XmlElement(qName));
         public void endElement(String uri, String localName, String qName) throws SAXException {
              XmlElement elem = elementStack.peek();
              if (elem.isEmpty) {
                   xmlBuilder.insert(xmlBuilder.length()-1, "/");
              } else {
                   xmlBuilder.append("</");
                   xmlBuilder.append(qName);
                   xmlBuilder.append(">");
              elementStack.pop();
         public void characters(char ch[], int start, int length) throws SAXException {
              if (!elementStack.empty()) {
                   XmlElement elem = elementStack.peek();
                   elem.setNotEmpty();
              String str = new String(ch, start, length);
              xmlBuilder.append(str);
         public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
              String str = new String(ch, start, length);
              xmlBuilder.append(str);
    }

  • XML - SAX Parsing Question

    Hi,
    I am parsing XML using SAX parser and fill the values into the HashTable ( like Key value pair ).. so i can get the vaues for a particular key using hash get function.
    For the following XML. There are 2 "subscriberNumber" attribute, one is under "sn:Subscriber" and the another is under "sn:SubscriberChange".
    I can able to put this values in hash table and when i print the Hash table it is printing as sn:subscriberNumber=[1234567890, 1234567890] .. But how will i know which one is from "sn:Subscriber" and which is from "sn:SubscriberChange"
    This is the XML :
    <sn:SubscriberNotification>
    <sn:notificationSubType>1120</sn:notificationSubType>
    <sn:Subscriber>
         <cng:PaymentType>PostPaid</cng:PaymentType>
         <sn:subscriberNumber>1234567890</sn:subscriberNumber>
    </sn:Subscriber>
    <sn:SubscriberChange>
         <sn:subscriberNumber>1234567890</sn:subscriberNumber>
    </sn:SubscriberChange>
    </sn:SubscriberNotification>
    Any suggestion and pointers are really helpful
    Thanks,
    -Raj..

    Try something like this:
    import java.util.Stack;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    class MyHandler extends DefaultHandler {
        Stack openTags = new Stack();
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            if (qName.equals("sn:subscriberNumber")) {
                String parentTag = (String)openTags.peek();
                System.out.println("Parent tag of this <sn:subscriberNumber> is : <" + parentTag + ">");
            openTags.push(qName);
        public void endElement(String uri, String localName, String qName) throws SAXException {
            openTags.pop();
    }Regards

  • Problem in parsing an XML using SAX parser

    Hai All,
    I have got a problem in parsing an XML using SAX parser.
    I have an XML (sample below) which need to be parsed
    <line-items>
    <item num="1">
         <part-number>PN1234</part-number>
         <quantity uom="ea">10</quantity>
         <lpn>LPN1060</lpn>
         <reference num="1">Line ref 1</reference>
         <reference num="2">Line ref 2</reference>
         <reference num="3">Line ref 3</reference>
    </item>
    <item num="2">
         <part-number>PN1527</part-number>
         <quantity uom="lbs">5</quantity>
         <lpn>LPN2152</lpn>
         <reference num="1">Line ref 1</reference>
         <reference num="2">Line ref 2</reference>
         <reference num="3">Line ref 3</reference>
    </item>
    <item num="n">
    </item>
    </line-items>
    There can be any number of items( 1 to n). I need to parse these
    item values using SAX parser and invoke a stored procedure for
    each item with its
    values(partnumber,qty,lpn,refnum1,refnum2,refnum3).
    Suppose if there are 100 items, i need to invoke the stored
    procedure sp1() 100 times for each item.
    I need to invoke the stored procedure in endDocument() method of
    SAX event handler and not in endelement() method.
    What is the best way to store those values and invoke the stored
    procedure in enddocument() method.
    Any help would br greatly appreciated.
    Thanks in advance
    Pooja.

    VO or ValueObject is a trendy new name for Beans.
    So just create an item class with variables for each of the sub elements.
    <item>
    <part-number>PN1234</part-number>
    <quantity uom="ea">10</quantity>
    <lpn>LPN1060</lpn>
    <reference num="1">Line ref 1</reference>
    <reference num="2">Line ref 2</reference>
    <reference num="3">Line ref 3</reference>
    </item>
    public class ItemVO
    String partNumber;
    int quantity;
    String quantityType;
    String lpn;
    List references = new ArrayList();
    * @return Returns the lpn.
    public String getLpn()
    return this.lpn;
    * @param lpn The lpn to set.
    public void setLpn(String lpn)
    this.lpn = lpn;
    * @return Returns the partNumber.
    public String getPartNumber()
    return this.partNumber;
    * @param partNumber The partNumber to set.
    public void setPartNumber(String partNumber)
    this.partNumber = partNumber;
    * @return Returns the quantity.
    public int getQuantity()
    return this.quantity;
    * @param quantity The quantity to set.
    public void setQuantity(int quantity)
    this.quantity = quantity;
    * @return Returns the quantityType.
    public String getQuantityType()
    return this.quantityType;
    * @param quantityType The quantityType to set.
    public void setQuantityType(String quantityType)
    this.quantityType = quantityType;
    * @return Returns the references.
    public List getReferences()
    return this.references;
    * @param references The references to set.
    public void setReferences(List references)
    this.references = references;

  • SAX Parser in OC4J

    I'm trying to read a XML file in an EJB using a SAX parser.
    I tried the following statement to create the reader
    XMLReader xr = XMLReaderFactory.createXMLReader("oracle.xml.parser.v2.SAXParser");
    but I obtain the following exception:
    java.lang.ClassNotFoundException: oracle.xml.parser.v2.SAXParser
    at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:118)
    The same works correctly from a command line application outside OC4J.
    Is there another SAX Parser I can use in OC4J?
    Andrea Mattioli

    I'm also seeing the a similar problem trying to get my EJB to parse SAX using the Xerces parser. If I do
    XMLReader myReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    and place xerces.jar into $(OC4J_INSTALL_ROOT)\j2ee\home\lib then at runtime I get
    java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
    This is despite the fact that calling Class.forName() on the same class name works fine. Setting the system property org.xml.sax.driver and calling createXMLReader with no parameters results in the same error.
    I can force use of the Xerces SAX parser by bypassing the factory and just calling
    XMLReader myReader = new org.apache.xerces.parsers.SAXParser();
    but that seems a tad hacky and I don't want to hardwire SAX parser implementation choice into my code.
    Is this a known bug?
    Also which parser is getting used by default in OC4J i.e. if I don't set org.xml.sax.driver and use the no parameters variant of createXMLReader()?
    Thanks
    Alan

  • RE: (forte-users) SAX Parser

    I would be interested to see TechNote 11811. I just tried the Fort&eacute; support
    web site and couldn't get it. Can anyone help?
    Thanks,
    Nick.
    -----Original Message-----
    From: Zee Khan [mailto:[email protected]]
    Sent: Tuesday, August 24, 1999 10:08 AM
    To: [email protected]
    Cc: [email protected]
    Subject: RE: (forte-users) SAX Parser
    Forte recommends not using DOM for 'documents with large
    number of tags'
    (TechNote 11811) so I am using SAX.
    Any thoughts/suggestions would be welcome,
    thanks,
    >From: "Jeanne Hesler" <[email protected]>
    >To: "'Zee Khan'" <[email protected]>,
    <[email protected]>
    >Subject: RE: (forte-users) SAX Parser
    >Date: Tue, 24 Aug 1999 08:48:23 -0500
    >
    >Out of curiosity, is it the node structure that you are
    trying to avoid,
    >or is it the DOM itself? Can you share some of your
    reasons? It would
    >seem to me that a node or tree structure would be ideally
    suited for
    >representing the complex structures that you describe.
    >
    >Jeanne
    >=====================================================
    >Jeanne Hesler <[email protected]>
    >MSF&W Software
    >Product Development
    >(217) 698-3535 ext. 207
    >http://www.msfw.com
    >=====================================================
    >/\ Imaging Developer - the only imaging product
    >\/ integrated into the Forte Development Environment
    >=====================================================
    >
    >
    >-----Original Message-----
    >From: Zee Khan [mailto:[email protected]]
    >Sent: Monday, August 23, 1999 10:32 AM
    >To: [email protected]
    >Subject: (forte-users) SAX Parser
    >
    >
    >I am using the SAX parser to parse some complex XML.
    >
    >My problem comes with complex data structures. There
    >are several embedded structures, how are these best
    >reflected with a SAX parser.
    >
    >(I guess one solution is to use DOM which returns
    >a node structure, but I want to avoid this)
    >
    >thanks in advace,
    >
    >
    >______________________________________________________
    >Get Your Private, Free Email at http://www.hotmail.com
    >
    >--
    >For the archives, go to:
    http://lists.sageit.com/forte-users
    >To unsubscribe send in a new email the word:
    >'Unsubscribe' to: [email protected]
    >
    >--
    >For the archives, go to:
    http://lists.sageit.com/forte-users and use
    >the login: forte and the password: archive. To unsubscribe,
    send in a new
    >email the word: 'Unsubscribe' to:
    [email protected]
    >
    Get Your Private, Free Email at http://www.hotmail.com
    For the archives, go to: http://lists.sageit.com/forte-users
    and use
    the login: forte and the password: archive. To unsubscribe,
    send in a new
    email the word: 'Unsubscribe' to:
    [email protected]

    I would be interested to see TechNote 11811. I just tried the Fort&eacute; support
    web site and couldn't get it. Can anyone help?
    Thanks,
    Nick.
    -----Original Message-----
    From: Zee Khan [mailto:[email protected]]
    Sent: Tuesday, August 24, 1999 10:08 AM
    To: [email protected]
    Cc: [email protected]
    Subject: RE: (forte-users) SAX Parser
    Forte recommends not using DOM for 'documents with large
    number of tags'
    (TechNote 11811) so I am using SAX.
    Any thoughts/suggestions would be welcome,
    thanks,
    >From: "Jeanne Hesler" <[email protected]>
    >To: "'Zee Khan'" <[email protected]>,
    <[email protected]>
    >Subject: RE: (forte-users) SAX Parser
    >Date: Tue, 24 Aug 1999 08:48:23 -0500
    >
    >Out of curiosity, is it the node structure that you are
    trying to avoid,
    >or is it the DOM itself? Can you share some of your
    reasons? It would
    >seem to me that a node or tree structure would be ideally
    suited for
    >representing the complex structures that you describe.
    >
    >Jeanne
    >=====================================================
    >Jeanne Hesler <[email protected]>
    >MSF&W Software
    >Product Development
    >(217) 698-3535 ext. 207
    >http://www.msfw.com
    >=====================================================
    >/\ Imaging Developer - the only imaging product
    >\/ integrated into the Forte Development Environment
    >=====================================================
    >
    >
    >-----Original Message-----
    >From: Zee Khan [mailto:[email protected]]
    >Sent: Monday, August 23, 1999 10:32 AM
    >To: [email protected]
    >Subject: (forte-users) SAX Parser
    >
    >
    >I am using the SAX parser to parse some complex XML.
    >
    >My problem comes with complex data structures. There
    >are several embedded structures, how are these best
    >reflected with a SAX parser.
    >
    >(I guess one solution is to use DOM which returns
    >a node structure, but I want to avoid this)
    >
    >thanks in advace,
    >
    >
    >______________________________________________________
    >Get Your Private, Free Email at http://www.hotmail.com
    >
    >--
    >For the archives, go to:
    http://lists.sageit.com/forte-users
    >To unsubscribe send in a new email the word:
    >'Unsubscribe' to: [email protected]
    >
    >--
    >For the archives, go to:
    http://lists.sageit.com/forte-users and use
    >the login: forte and the password: archive. To unsubscribe,
    send in a new
    >email the word: 'Unsubscribe' to:
    [email protected]
    >
    Get Your Private, Free Email at http://www.hotmail.com
    For the archives, go to: http://lists.sageit.com/forte-users
    and use
    the login: forte and the password: archive. To unsubscribe,
    send in a new
    email the word: 'Unsubscribe' to:
    [email protected]

  • SAX parser getValue() method

    All,
    Whever i get the attribute value using getValue() method , it returns me the result with the lower case string
    for example if i have something like this
    <input label="Last Name:" />
    and i try to get the attribute value of label
    String label = attrs.getValue("label");
    The result will be
    label = "last name"
    It doesnot adhere with the case (it returns the value by converting it into lower case)
    Is it something that i am doing wrong , or its the way SAX parser internally does it.
    I am using the SAX parser which comes with the BlackBerry JDE.
    Any answers , pointers will be helpful

    Never mind , my input to the SAX parser itself is somehow getting all lower case.
    Thanks!

Maybe you are looking for

  • Updated to 10.10.3 and now iPhoto won't open

    I upgraded the OS 10.10.3 and now iPhoto won't open. It says "the version of iPhoto installed on this Mac is not compatible with OS X Yosemite.  Download the latest version for free from the Mac App Store."  However, when I go to the Mac App Store, t

  • Auto detect missing java plugin with Netscape

    How do I get Netscape to automatically detect that it is missing the Java Plugin, and go to Sun's download page? I have IE 5.5 and Netscape 7 installed. My html looks like this: <OBJECT classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase

  • Need code for sql update

    HI All, i have table with data like this select '[email protected]' mgr, null mgr1,null mgr2,null mgr3,'[email protected]:[email protected]:[email protected]'mgrfull from dual; 1)mgrfull column have with : sepreated email ,here last email split and u

  • Invoice verification for SAP R/3 - Define Start logo

    All, Does anyone know how to correctly upload a logo that seperates different company codes? THe configuration path is as followed: SPRO-Material Management-Logistic Invoice Verification-Incoming Invoice-Define Start Logo I can configure it fine, as

  • Js files Problem

    Im working with js files but where should i put the file in, because in resources, creator dont recognize it, and how should i linked to the proyect in the jsp code