Sax problem

hi guys
how can i find id value of href with sax
i have such a code block
<a href="showthread.php?t=74134" id="thread_title_74134" style="font-weight: bold;">Compatible Windows Vista 64-bit games</a>and while parsing i wann a check id attribute of link
regards
cem

In your startElement() method there's a parameter which returns an Attributes object. Use that to find the value of a particular attribute in the element.

Similar Messages

  • SAX problem(plz see the code given)

    hi all,
    i am using SAX parser for validating my xml file against the dtd,i am getting some errors that i am not able to make out.cud u plz help me.i am sending u my files.
    ------------------------java file------------------------------------
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    public class Echo extends DefaultHandler
    public static void main(String argv[]){
    if (argv.length != 1) {
    System.err.println("Usage: cmd filename");
    System.exit(1);
    // Use an instance of ourselves as the SAX event handler
    //DefaultHandler handler=new DefaultHandler();
    Echo handler=new Echo();
    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    try {
    // Set up output stream
    out = new OutputStreamWriter(System.out, "UTF8");
    // Parse the input
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse( new File(argv[0]), handler );
    catch (SAXParseException spe) {
    // Error generated by the parser
    System.out.println("\n** Parsing error"
    + ", line " + spe.getLineNumber()
    + ", uri " + spe.getSystemId());
    System.out.println(" " + spe.getMessage() );
    }catch (Throwable t){
    t.printStackTrace();
    System.exit(0);
    static private Writer out;
    public void startDocument()
    throws SAXException{
    emit("<?xml version='1.0' encoding='UTF-8'?>");
    nl();
    public void endDocument()
    throws SAXException{
    try {
    nl();
    out.flush();
    }catch (IOException e) {
    throw new SAXException("I/O error", e);
    public void startElement(String namespaceURI,
    String sName, // simple name (localName)
    String qName, // qualified name
    Attributes attrs)
    throws SAXException
    String eName = sName; // element name
    if ("".equals(eName)) eName = qName; // namespaceAware = false
    emit("<"+eName);
    if (attrs != null) {
    for (int i = 0; i < attrs.getLength(); i++) {
    String aName = attrs.getLocalName(i); // Attr name
    if ("".equals(aName)) aName = attrs.getQName(i);
    emit(" ");
    emit(aName+"=\""+attrs.getValue(i)+"\"");
    emit(">");
    public void endElement(String namespaceURI,
    String sName, // simple name
    String qName // qualified name
    throws SAXException
    emit("</"+qName+">");
    public void characters(char buf[], int offset, int len)
    throws SAXException
    String s = new String(buf, offset, len);
    emit(s);
    public void ignorableWhitespace(char buf[], int offset, int Len)
    throws SAXException
    nl();
    //emit("IGNORABLE");
    private void emit(String s)
    throws SAXException
    try {
    out.write(s);
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    private void nl()
    throws SAXException
    String lineEnd = System.getProperty("line.separator");
    try {
    out.write(lineEnd);
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    public void error(SAXParseException e)
    throws SAXParseException
    throw e;
    public void warning(SAXParseException e)throws SAXParseException{
    System.out.println("WARNING : Line Number:- "+e.getLineNumber());
    System.out.println("WARNING : Column Number:- "+e.getColumnNumber());
    System.out.println("WARNING : System ID:- "+e.getSystemId());
    System.out.println("WARNING : Public Number:- "+e.getPublicId());
    --------------------------xml file------------------------------------
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE slideshow SYSTEM "echo.dtd">
    <!-- A SAMPLE set of slides -->
    <slideshow
    title="Sample Slide Show"
    date="Date of publication"
    author="Yours Truly"
    >
    <![CDATA[Digram : frobmorten <------------ fuznaten
    | <3> ^
    | <1> | <1> = fozzle
    V | <2> = framboze
    Staten+ <3> = frenzle
    <2>
    ]]>
    <!-- TITLE SLIDE -->
    <slide type="all">
    <image src="my.gif" alt="this is my pic" type="image/gif"/>
    <title>Wake up to WonderWidgets!</title>
    </slide>
    <!-- OVERVIEW -->
    <slide type="all">
    <title>Overview</title>
    <item>WonderWidgets are great</item>
    <item/>
    <item>Who buys WonderWidgets</item>
    </slide>
    <slide type="all">
    <title>Overview</title>
    <item>Who buys WonderWidgets</item>
    </slide>
    </slideshow>
    -----------------------------dtd file---------------------------------
    <!ELEMENT slideshow (slide+)>
    <!ATTLIST slideshow
    title CDATA #IMPLIED
    date CDATA #IMPLIED
    author CDATA #IMPLIED
    >
    <!ELEMENT slide (image?,title, item*)>
    <!ATTLIST slide type CDATA #IMPLIED>
    <!ELEMENT title (#PCDATA)>
    <!ELEMENT item (#PCDATA | item)* >
    <!ELEMENT image EMPTY>
    <!ATTLIST image
    alt CDATA #IMPLIED
    src CDATA #REQUIRED
    type CDATA "image/gif"
    >
    -----------------------ERROR I AM GETTING IS--------------------------
    <?xml version='1.0' encoding='UTF-8'?>
    <slideshow title="Sample Slide Show" date="Date of publication" author="Yours Tr
    uly">
    Digram : frobmorten <------------ fuznaten
    | <3> ^
    | <1> | <1> = fozzle
    V | <2> = framboze
    Staten+ <3> = frenzle
    <2>
    <slide type="all">
    <image src="my.gif" alt="this is my pic" type="image/gif"></image>
    <title>Wake up to WonderWidgets!</title>
    </slide>
    <slide type="all">
    <title>Overview</title>
    <item>WonderWidgets are great</item>
    <item></item>
    <item>Who buys WonderWidgets</item>
    </slide>
    <slide type="all">
    <title>Overview</title>
    <item>Who buys WonderWidgets</item>
    </slide>
    org.xml.sax.SAXException: The content of element type "slideshow" must m
    atch "(slide)+".
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.j
    ava:979)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at Echo.main(Echo.java:28)
    with my lot efforts i am not able to make out where i am wrong,plz do have a look on the codes.
    thanx in advance
    best regards
    anshul

    Hi i have consulted the XML spec and it is not possible to have a CDATA section as element content. A element declaration can have only content that is empty, ANY (i.e. can include any other declared elements in DTD), mixed (i.e. can contain PCDATA or child elements, or child elements. An element cannot include any character data which CDATA represents. i.e it is not valid to do <!ELEMENT slideshow CDATA>
    The CDATA can only be used with an attribute declaration. Regard CDATA as a type definition for any attribute variables.
    So what do i suggest. You could declare a separate element which has an attribute for the CDATA section
    <!ELEMENT input (Name)>
    <!ATTLIST input instructions CDATA #REQUIRED>
    hope this helps.

  • SAX problem with jaxp

    Hi all
    I tried the JAXP but I have this error: could anyone help? Thanks a lot (my java code is under the error)
    Thanks
    Cecile
    Exception in thread "main" org.xml.sax.SAXParseException: org.apache.crimson.parser/P-076 Malformed UTF-8 char -- is an
    XML encoding declaration missing?
    at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1038)
    at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1010)
    at org.apache.crimson.parser.InputEntity.peek(InputEntity.java, Compiled Code)
    at org.apache.crimson.parser.Parser2.peek(Parser2.java:2927)
    at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:999)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java, Compiled Code)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:346)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:232)
    at sivpn.ChargementSAX.main(ChargementSAX.java:521)
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse("toto.xml", handler );

    The error is in your XML input, not in your Java code. Probably the XML doesn't declare its encoding, so the parser assumes that it is encoded in UTF-8. And probably it contains some character (like an accented letter, for example) that is not part of the UTF-8 encoding. So contact the person who created the XML -- which is not well-formed XML, by the way -- and get them to fix it. It's possible that declaring the encoding as ISO8859-1 might work, but it might not. All depends on what the invalid character is.

  • XML SAX dtd Validation Problem

    Hi,
              I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
              When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
              Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
              Code Snippet:
              boolean isValid = false;
              try {
              // Create and configure factory
              SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
              factory.setValidating(true);
              factory.setNamespaceAware(true);
              // To be notified of validation errors in the XML document,
              // add a custom error handler to the document builder
              PIMSFeedFileValidationHandler handler
              = new PIMSFeedFileValidationHandler();
              // Create and Configure Parser
              SAXParser parser = factory.newSAXParser();
              parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
              parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
              // Set reader with entityResolver for dtd
              XMLReader xmlReader = parser.getXMLReader();
              xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
              // convert file to URL, as it is a remote file
              URL url = super.getFile().toURL();
              // Open an input stream and parse
              InputStream is = url.openStream();
              xmlReader.setErrorHandler(handler);
              xmlReader.parse(new InputSource(is));
              is.close();
              // get the result of parsing the document by checking the
              // errorhandler's isValid property
              isValid = handler.isValid();
              if (!isValid) {
              LOGGER.warn(handler.getMessage());
              LOGGER.debug("XML file is valid XML? " + isValid);
              } catch (ParserConfigurationException e) {
              LOGGER.error("Error parsing file", e);
              } catch (SAXException e) {
              LOGGER.error("Error parsing file", e);
              } catch (IOException e) {
              throw new FeedException(e);
              return isValid;
              See stack trace below for a little more info.
              2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
              2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
              VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
              2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
              2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
              org.xml.sax.SAXParseException: Element type "Session" must be declared.
              org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
              org.xml.sax.SAXParseException: Element type "Volume" must be declared.
              org.xml.sax.SAXParseException: Element type "Written" must be declared.
              org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
              org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
              … continues for all the elements in the doc
              2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
              2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
              Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
              Thanks in Advance
              Adam

    It looks like you clicked on "Post" before you got around to explaining your problem. I don't see any error messages or any description of what was supposed to happen and what happened instead.
    Now, I don't know anything about XML Schema, but just guessing at how that unique name feature might be designed, and just guessing that your unique name is actually in the <userId> element, I would suggest that this:
    <xsd:unique name="un_name"> 
      <xsd:selector xpath="USER"/> 
      <xsd:field xpath="."/> 
    </xsd:unique> is at fault because it doesn't mention the <userId> element anywhere.

  • Sax parser problem

    hi,
    i am assuming the problem is with sax parser but i cant be sure. I am parsing a xml file (about 1.4MB) with some data in it. the parser i have created reads the xml file correctly for the most part but when at some point the
    "public void characters(char buf[], int offset, int len) throws SAXException"
    function stops working correctly....i.e it doesnt fully read read the data between the "<start>" and "</start>" element. say it reads about 100 id's correctly---for 101 ID it does this. This is just an example. Since, the problem might be with how :
    "public void characters(char buf[], int offset, int len) throws SAXException"
    function is reading the data i was wondering if anybody else had encountered this problem or please let me know if i need to change something in the code: here's a part of the code :
    Bascially i have created three classes to enter data into three mysql tables and as i parse the data i fill up the columns by matching the column header with the tagName.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.*;
    import java.io.*;
    import java.util.ArrayList;
    import java.lang.Object;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import java.util.*;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    public class Echo03 extends DefaultHandler
    StringBuffer textBuffer;
    int issuedValue, prodValue;
    OrdHeader header = new OrdHeader();
    OrdDetail detail = new OrdDetail();
    Member memInfo = new Member();
    //new addition to store the dynamic value of the products
    TestOrdheader prod = new TestOrdheader();
    int counter;
    String tag, newTag;
    SetValue setVal = new SetValue();
    String test;
    public static void main(String argv[])
    if (argv.length != 1) {
    System.err.println("Usage: cmd filename");
    System.exit(1);
    // Use an instance of ourselves as the SAX event handler
    DefaultHandler handler = new Echo03();
    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
    // Set up output stream
    out = new OutputStreamWriter(System.out, "UTF8");
    // Parse the input
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse( new File(argv[0]), handler);
    } catch (Throwable t) {
    t.printStackTrace();
    System.exit(0);
    static private Writer out;
    private String indentString = " "; // Amount to indent
    private int indentLevel = 0;
    //===========================================================
    // SAX DocumentHandler methods
    //===========================================================
    public void startDocument()
    throws SAXException
    nl();
    nl();
    emit("START DOCUMENT");
    nl();
    emit("<?xml version='1.0' encoding='UTF-8'?>");
    header.assign();
    public void endDocument()
    throws SAXException
    nl(); emit("END DOCUMENT");
    try {
    nl();
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    public void startElement(String namespaceURI,
    String lName, // local name
    String qName, // qualified name
    Attributes attrs)
    throws SAXException
    indentLevel++;
    nl(); //emit("ELEMENT: ");
    String eName = lName; // element name
    if ("".equals(eName)) eName = qName; // namespaceAware = false
    if (qName.equals("Billing")){
    issuedValue = 1;
    }else if (qName.equals("Shipping")){
    issuedValue = 2;
    }else if (qName.equals("ShippingTotal")){
    issuedValue = 3;
    //check to see if "Product" is the name of the element thats coming next
    if (qName.equals("Product")){
    if (issuedValue != 3){
    prodValue = 1;
    prod.addCounter();
    }else{
    prodValue = 0;
    tag = eName;
    if (attrs != null) {
    for (int i = 0; i < attrs.getLength(); i++) {
    String aName = attrs.getLocalName(i); // Attr name
    if ("".equals(aName)) aName = attrs.getQName(i);
    nl();
    emit(" ATTR: ");
    emit(aName);
    emit("\t\"");
    emit(attrs.getValue(i));
    emit("\"");
    if (attrs.getLength() > 0) nl();
    public void endElement(String namespaceURI,
    String sName, // simple name
    String qName // qualified name
    throws SAXException
    nl();
    String eName = sName; // element name
    if ("".equals(eName)){
    eName = qName; // not namespaceAware
    if ("Order".equals(eName)){          
    //enter into database
         databaseEnter();
    textBuffer = null;
    indentLevel--;
    public void characters(char buf[], int offset, int len)
    throws SAXException
    nl();
    try {
    String s = new String(buf, offset, len);
    if (!s.trim().equals("")){
    settag(tag, s);
    s = null;
    }catch (NullPointerException E){
    System.out.println("Null pointer Exception:"+E);
    //===========================================================
    // Utility Methods ...
    //===========================================================
    // Wrap I/O exceptions in SAX exceptions, to
    // suit handler signature requirements
    private void emit(String s)
    throws SAXException
    try {
    out.write(s);
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    // Start a new line
    // and indent the next line appropriately
    private void nl()
    throws SAXException
    String lineEnd = System.getProperty("line.separator");
    try {
    out.write(lineEnd);
    for (int i=0; i < indentLevel; i++) out.write(indentString);
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    ===================================================================
    ///User defined methods
    ===================================================================
    private String strsplit(String splitstr){
    String delimiter = new String("=");
    String[] value = splitstr.split(delimiter);
    value[1] = value[1].replace(':', ' ');
    return value[1];
    public void settag(String tag, String s){         
    String pp_transid = null, pp_respmsg = null,pp_authid = null, pp_avs = null, pp_avszip = null;
    if ((tag.equals("OrderDate")) || (tag.equals("OrderProcessingInfo"))){
    if (tag.equals("OrderDate")){
    StringTokenizer st = new StringTokenizer(s);
    String orddate = st.nextToken();
    String ordtime = st.nextToken();
    header.put("ordDate", orddate);
    header.put("ordTime", ordtime);
    }else if (tag.equals("OrderProcessingInfo")){
    StringTokenizer st1 = new StringTokenizer(s);
    int tokenCount = 1;
    while (tokenCount <= st1.countTokens()){
    switch(tokenCount){
    case 1:
    String extra = st1.nextToken();
    break;
    case 2:
    String Opp_transid = st1.nextToken();
    pp_transid = strsplit(Opp_transid);
    break;
    case 3:
    String Opp_respmsg = st1.nextToken();
    pp_respmsg = strsplit(Opp_respmsg);
    break;
    case 4:
    String Opp_authid = st1.nextToken();
    pp_authid = strsplit(Opp_authid);
    break;
    case 5:
    String Opp_avs = st1.nextToken();
    pp_avs = strsplit(Opp_avs);
    break;
    case 6:
    String Opp_avszip = st1.nextToken();
    pp_avszip = strsplit(Opp_avszip);
    break;
    tokenCount++;
    header.put("pp_transid", pp_transid);
    header.put("pp_respmsg", pp_respmsg);
    header.put("pp_authid", pp_authid);
    header.put("pp_avs", pp_avs);
    header.put("pp_avszip", pp_avszip);
    }else{
    newTag = new String(setVal.set_name(tag, issuedValue));
    header.put(newTag, s);
    //detail.put(newTag, s);
    prod.put(newTag, s);
    memInfo.put(newTag,s);
    //Check to see-- if we should add this product to the database or not
    boolean check = prod.checkValid(newTag, prodValue);
    if (check){
    prod.addValues(s);
    setVal.clearMod();
    ==================================================================
    Here's the error that i get:
    java.util.NoSuchElementException
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:281)
    at Echo03.main(Echo03.java:47)

    I haven't gone through your code but I also had a similar error....and the exception in my was because of an "&" instead of the entity reference & in one of the element values. I use a non-validating parser but if you use a validating one then this might not be the reason for your exception.

  • Problem in error handling in SAX Parser

    My application takes xml message as input.
    If a error was found while validating, an <Errors> <Error></Error></Errors> element is included in the orginal message and send back to the user.
    While validation xml message I found an interesting problem.
    Created a false entry for the root element attribute.
    Traced method invocation.
    First the call back error method is invoked,then the start element(stored the attributes inside the starElement to a instance variable).When i tried to print the attribute .As the error method got invoked first
    if showed "null".
    But when i created the same case with the child elements attributes
    even though invoking of the methods happens in the same sequence
    attributes got assigned and can print the attibutes values.
    xml is schema vaidated .Is there any restriction that root element should not contain attributes.Can any one explain how the call back methods are invoked .
    Regards
    Dheeraj
    // import statements here
    public class OperationHandler extends DefaultHandler {
         private static Logger logger = Logger.getLogger(OperationHandler.class.getName());
         private Attributes attributes;
         private StringBuffer dataStore;
    public OperationHandler() {
    dataStore = new StringBuffer(100);
         * Receive notification of the end of an document.
         public void startDocument() {
              logger.debug("OperationHandler: startDocument");
         * Receive notification of the beginning of the element.
         public void startElement(String uri, String lName,
                                            String qName, Attributes attributes) {
              logger.debug("OperationHandler: startElement" + lName);
              dataStore.setLength(0);
         * Receive notification of the end of an element.
         public void endElement(String uri, String lName, String qName) {
              logger.debug("OperationHandler: endElement");
              // bussiness specific code
         * Receive notification of the end of an document.
         public void endDocument() {
              logger.debug("OperationHandler: endDocument");
         public void error(SAXParseException saxe) {
              logger.debug("OperationHandler : error");
              System.out.println("CurrentElement"+currentElement +" "+"Attributes" + attributes);
                   if(attributes != null) {
                        for(int i=0; i < attributes.getLength(); i++) {
                             System.out.println(saxe.getColumnNumber());
                             System.out.println(saxe.getLineNumber());
                             System.out.println(saxe.getMessage());
         public void fatalError(SAXParseException saxe) throws SAXException {
              logger.debug("Fatal error while parsing message");
              logger.error("Error " + saxe.getMessage() );
         public void warning(SAXParseException saxe) throws SAXException {
              logger.warn("Warning " + saxe.getMessage() );
         * Receive notification of character data inside an element.
         public void characters(char[] charData,int start, int length) {
              String strData = new String(charData, start, length);
              if(strData != null) {
                   strData.trim();
                   dataStore.append(strData);
    }

    Hi Muruganand,
    Is the data load failing while loading data or while activating?
    if the data load is failing at activation, thers is nothing you can do except editing the records in PSA and then update them.
    As far as i have seen, the data load to DSO fails in Activation and not while loading. this is the reason why the records are not collected in error stack
    unlike if it is a cube, the data load fails while loading collecting the recods in error stack.
    hope this helps,
    Thanks and Regards,
    Srinath.

  • Problem in SAX Java mapping

    Hi,
    I'm using SAX Java mapping in one scenario. Problem is when I get some Croatina characters, like Đ or u0160,
    output XML is not valid. XML Spy complains, IE complains and so on. Customer is sure  that data ( XML in CLOB field in Oracle DB) is UTF-8? What could be a problem?
    What I'm doing is reading entire XML into string with help of BufferedReader, then do some manipulation and write String into byte array with:
                   byte[] bytes = file.toString().getBytes("UTF-8");
                   saxParser.parse(new ByteArrayInputStream(bytes), handler);
    and then of course parse XML. readLine method reads data and problematic is "Ä�" - ￯0 - 0xC490.
    For this character XML Spy doesn't complain, IE also. After conversion, this character looks like "Ä?" - 0xC43F, and this is not good any more. Why?

    Hi Stefan,
    I've finally done it. Code as foollws:
         public void execute(InputStream in, OutputStream out)
                   throws com.sap.aii.mapping.api.StreamTransformationException {
              DefaultHandler handler = this;
              SAXParserFactory factory = SAXParserFactory.newInstance();
              try {
                   SAXParser saxParser = factory.newSAXParser();
                   fStreamOut = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
                   encoding = "UTF-8";
                   if (map != null) {
                        mappingTrace = (MappingTrace) map
                                  .get(StreamTransformationConstants.MAPPING_TRACE);
                   InputStreamReader is = new InputStreamReader(in, "UTF8");
                   BufferedReader reader = new BufferedReader(is);
                   StringBuffer file = new StringBuffer();
                   String line = new String();
                   try {
                        while ((line = reader.readLine()) != null) {
                             file.append(line);
                   } catch (IOException e) {
                        e.printStackTrace();
                   } finally {
                        try {
                             in.close();
                        } catch (IOException e) {
                             e.printStackTrace();
                   Date d4 = new Date();
                   file = replaceREGEX(
                             "<\\?xml version=\"1\\.0\" encoding=\"UTF-8\"\\?>", "",
                             file);
                   char[] cArray = file.toString().toCharArray();
                   Date filedat = new Date();;
                   SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
                   String fName = df.format(filedat) + "_El_Invoice.xml";
                   Writer out1 = new BufferedWriter(new OutputStreamWriter(
                             new FileOutputStream(fName), "UTF8"));
                   try {
                        out1.write(file.toString().toCharArray());
                        out1.close();
                   } catch (UnsupportedEncodingException e) {
                   } catch (IOException e) {
                   saxParser.parse(fName, handler);
                   File outFile = new File(fName);
                   outFile.delete();
              } catch (Throwable t) {
                   if (mappingTrace != null) {
                        mappingTrace.addInfo(t.toString());
                   t.printStackTrace();
    problem was also in method for writing in output stream, so I've changed it:
         private void printOutPut(String sOP) {
              try {
                      //    fStreamOut.write(sOP.getBytes());
                   fStreamOut.write(sOP);
              } catch (IOException e) {
                   e.notify();

  • 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;

  • Problem in using SAX parser.

    Hai All,
    I have got a problem in using SAX parser.
    My XML looks like this:
    <authorizer>
    <first-name>HP</first-name>
    <last-name>Services</last-name>
    <phone>800-22-1984</phone>
    </authorizer>
    <destination>
    <first-name>John</first-name>
    <last-name>Doe</last-name>
    <company>John Doe Enterprises, Inc.</company>
    <department>Manufacturing</department>
    <phone>800-555-1234</phone>
    <address>
    <street-one>1654 Peachtree Str</street-one>
    <street-two>Suite Y</street-two>
    <city>Atlanta</city>
    <province>GA</province>
    <country>US</country>
    <postal-code>30326</postal-code>
    </address>
    </destination>
    my part of SAX parser code is:
    public void startElement (String name, AttributeList attrs)
    throws SAXException
    accumulator.setLength(0);
    public void characters (char buf [], int offset, int len)
    throws SAXException
    accumulator.append(buf, offset, len);
    public void endElement (String name)
    throws SAXException
    if (name.equals("first-name") )
    firstname=accumulator.toString().trim();
    if (name.equals("last-name"))
    lastname=accumulator.toString().trim();
    My problem is that i have to store the values of first-name and last-name.
    but i have that in both
    <authorizer> </authorizer> Tag and
    <destination> </destination>
    I need to retrive authorizer's firstname,lastname and
    destination's firstname and lastname.
    what i mean is i need to store authorizerFirstName,authorizerLastName
    destinationFirstname and destinationLastname.
    Pls let me know how to do that.
    Thanks in advance.
    Pooja.

    hi pooja,
    I think you are using DataHandler for parsing. Its deprecated. try using contentHandler . You can get the value of the element at the beginning. say for example
    <firstname>sdfs</firstname>
    the startElement will be firstname
    the next method that it invokes will be characters method which has the text associated with the element. I am sending a sample code for your problem. try using it .
    boolean m_boolinAuth = false;
    boolean m_boolinDest = false;
    boolean m_bAuthFName = false;
    boolean m_bAuthLName = false;
    public void startElement(String namespaceURI, String elementName, String qName, Attributes atts)
    //does the logic for startElement
    if(qName.equals("Authorization"))
    m_boolinAuth = true;
    m_boolinDest = false;
    else if(qName.equals("Destination"))
    m_boolinDest = true;
    m_boolinAuth = false;
    if(qName.equals("firstname"))
    m_bFirstName = true;
    if(qName.equals("lastname"))
    m_bLastName = true;
    public void characters(char[] ch, int start, int length)
    //does the logic for characters.
    String str = new String(ch,start,length);
    if(m_bFirstName)
    if(m_boolinAuth)
    m_strAuthFirstName =str;
    else if(m_boolinDest)
    m_strDestFirstName = str;
    m_bFirstName = false;
    if(m_bLastName)
    //same as first name case;
    }

  • 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 Java problem

    Hi,
    This is my first time to your forum. I would be grateteful if some one could tell me where Im going wrong.
    My program use a SAX parser in a Java application. It should read an XML file and extract cetain attibutes if they appear.
    Here is the program.
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import javax.xml.parsers.*;
    public class PacketValues extends DefaultHandler {
    public static void main(String[] arguments) {
    if (arguments.length ==1) {
    PacketValues pv = new PacketValues(arguments[0]);
    } else {
    System.out.println("input just the xml file please");
    PacketValues(String xmlFile) {
    File input = new File(xmlFile);
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    try {
    SAXParser sax = factory.newSAXParser();
    PacketValueProcessor pvp = new PacketValueProcessor();
    sax.parse(input, pvp);
    System.out.println("The value is " + pvp.a);
    } catch (ParserConfigurationException pce) {
    System.out.println("Could not create that parser. ");
    System.out.println(pce.getMessage());
    } catch (SAXException se) {
    System.out.println("Problem with the SAX parser. ");
    System.out.println(se.getMessage());
    } catch (IOException ioe) {
    System.out.println("Error reading file.");
    System.out.println(ioe.getMessage());
    class PacketValueProcessor extends DefaultHandler {
    String a;
    PacketValueProcessor() {
    super();
    public void startElement(String URI, String localName,
    String qName, Attributes atts) {
    System.out.println("here in startElement");
    if (localName.equals("field")) {
    System.out.println("localname equals field");
    String n = atts.getValue("","name");
    System.out.println("n is " + n);
    if (n.equals("timestamp")) {
    String a = atts.getValue("","value");
    System.out.println("a is " + a);
    if (n.equals("tcp.seq")) {
    String a = atts.getValue("","value");
    System.out.println("a is " + a);
    It aims to extract both the value of a field element which has a name attribute "timestamp" and the value of a field element which has the attribute "tcp.seq".
    Here is part of the xml file
    <?xml version="1.0"?>
    <pdml version="0" creator="ethereal/0.10.0">
    <packet>
    <proto name="geninfo" pos="0" showname="General information" size="74">
    <field name="num" pos="0" show="1" showname="Number" value="1" size="74"/>
    <field name="len" pos="0" show="74" showname="Packet Length" value="4a" size="74"/>
    <field name="caplen" pos="0" show="74" showname="Captured Length" value="4a" size="74"/>
    <field name="timestamp" pos="0" show="Jan 22, 2004 12:04:58.646896000" showname="Captured Time" value="1074773098.646896000" size="74"/>
    </proto>
    <proto name="frame" showname="Frame 1 (74 bytes on wire, 74 bytes captured)" size="74" pos="0">
    <field name="frame.marked" showname="Frame is marked: False" size="0" pos="0" show="0"/>
    <field name="frame.time" showname="Arrival Time: Jan 22, 2004 12:04:58.646896000" size="0" pos="0" show="Jan 22, 2004 12:04:58.646896000"/>
    <field name="frame.time_delta" showname="Time delta from previous packet: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
    <field name="frame.time_relative" showname="Time since reference or first frame: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
    <field name="frame.number" showname="Frame Number: 1" size="0" pos="0" show="1"/>
    <field name="frame.pkt_len" showname="Packet Length: 74 bytes" size="0" pos="0" show="74"/>
    <field name="frame.cap_len" showname="Capture Length: 74 bytes" size="0" pos="0" show="74"/>
    </proto>
    <proto name="eth" showname="Ethernet II, Src: 00:05:5d:6d:a0:87, Dst: 00:50:da:4f:6d:83" size="14" pos="0">
    <field name="eth.dst" showname="Destination: 00:50:da:4f:6d:83 (3com_4f:6d:83)" size="6" pos="0" show="00:50:da:4f:6d:83" value="0050da4f6d83"/>
    <field name="eth.src" showname="Source: 00:05:5d:6d:a0:87 (D-Link_6d:a0:87)" size="6" pos="6" show="00:05:5d:6d:a0:87" value="00055d6da087"/>
    <field name="eth.addr" showname="Source or Destination Address: 00:50:da:4f:6d:83 (3com_4f:6d:83)" size="6" pos="0" show="00:50:da:4f:6d:83" value="0050da4f6d83"/>
    <field name="eth.addr" showname="Source or Destination Address: 00:05:5d:6d:a0:87 (D-Link_6d:a0:87)" size="6" pos="6" show="00:05:5d:6d:a0:87" value="00055d6da087"/>
    <field name="eth.type" showname="Type: IP (0x0800)" size="2" pos="12" show="0x0800" value="0800"/>
    </proto>
    <proto name="ip" showname="Internet Protocol, Src Addr: 192.168.2.21 (192.168.2.21), Dst Addr: 192.168.3.10 (192.168.3.10)" size="20" pos="14">
    <field name="ip.version" showname="Version: 4" size="1" pos="14" show="4" value="45"/>
    <field name="ip.hdr_len" showname="Header length: 20 bytes" size="1" pos="14" show="20" value="45"/>
    <field name="ip.dsfield" showname="Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)" size="1" pos="15" show="0" value="00">
    <field name="ip.dsfield.dscp" showname="0000 00.. = Differentiated Services Codepoint: Default (0x00)" size="1" pos="15" show="0x00" value="00"/>
    <field name="ip.dsfield.ect" showname=".... ..0. = ECN-Capable Transport (ECT): 0" size="1" pos="15" show="0" value="00"/>
    <field name="ip.dsfield.ce" showname=".... ...0 = ECN-CE: 0" size="1" pos="15" show="0" value="00"/>
    </field>
    <field name="ip.len" showname="Total Length: 60" size="2" pos="16" show="60" value="003c"/>
    <field name="ip.id" showname="Identification: 0xd779 (55161)" size="2" pos="18" show="0xd779" value="d779"/>
    <field name="ip.flags" showname="Flags: 0x04" size="1" pos="20" show="0x04" value="40">
    <field name="ip.flags.df" showname=".1.. = Don't fragment: Set" size="1" pos="20" show="1" value="40"/>
    <field name="ip.flags.mf" showname="..0. = More fragments: Not set" size="1" pos="20" show="0" value="40"/>
    </field>
    <field name="ip.frag_offset" showname="Fragment offset: 0" size="2" pos="20" show="0" value="4000"/>
    <field name="ip.ttl" showname="Time to live: 64" size="1" pos="22" show="64" value="40"/>
    <field name="ip.proto" showname="Protocol: TCP (0x06)" size="1" pos="23" show="0x06" value="06"/>
    <field name="ip.checksum" showname="Header checksum: 0xdcd2 (correct)" size="2" pos="24" show="0xdcd2" value="dcd2"/>
    <field name="ip.src" showname="Source: 192.168.2.21 (192.168.2.21)" size="4" pos="26" show="192.168.2.21" value="c0a80215"/>
    <field name="ip.addr" showname="Source or Destination Address: 192.168.2.21 (192.168.2.21)" size="4" pos="26" show="192.168.2.21" value="c0a80215"/>
    <field name="ip.dst" showname="Destination: 192.168.3.10 (192.168.3.10)" size="4" pos="30" show="192.168.3.10" value="c0a8030a"/>
    <field name="ip.addr" showname="Source or Destination Address: 192.168.3.10 (192.168.3.10)" size="4" pos="30" show="192.168.3.10" value="c0a8030a"/>
    </proto>
    <proto name="tcp" showname="Transmission Control Protocol, Src Port: 32862 (32862), Dst Port: 5001 (5001), Seq: 0, Ack: 0, Len: 0" size="40" pos="34">
    <field name="tcp.srcport" showname="Source port: 32862 (32862)" size="2" pos="34" show="32862" value="805e"/>
    <field name="tcp.dstport" showname="Destination port: 5001 (5001)" size="2" pos="36" show="5001" value="1389"/>
    <field name="tcp.port" showname="Source or Destination Port: 32862" size="2" pos="34" show="32862" value="805e"/>
    <field name="tcp.port" showname="Source or Destination Port: 5001" size="2" pos="36" show="5001" value="1389"/>
    <field name="tcp.len" showname="TCP Segment Len: 0" size="4" pos="34" show="0" value="805e1389"/>
    <field name="tcp.seq" showname="Sequence number: 0" size="4" pos="38" show="0" value="8dc936ab"/>
    <field name="tcp.hdr_len" showname="Header length: 40 bytes" size="1" pos="46" show="40" value="a0"/>
    <field name="tcp.flags" showname="Flags: 0x0002 (SYN)" size="1" pos="47" show="0x02" value="02">
    <field name="tcp.flags.cwr" showname="0... .... = Congestion Window Reduced (CWR): Not set" size="1" pos="47" show="0" value="02"/>
    <field name="tcp.flags.ecn" showname=".0.. .... = ECN-Echo: Not set" size="1" pos="47" show="0" value="02"/>
    <field name="tcp.flags.urg" showname="..0. .... = Urgent: Not set" size="1" pos="47" show="0" value="02"/>
    <field name="tcp.flags.ack" showname= etc etc
    The output is
    here in startElement
    here in startElement
    here in startElement
    here in startElement
    here in startElement
    here in startElement
    here in startElement
    here in startElement
    etc
    etc
    here in startElement
    here in startElement
    The value is null
    this of course means that all the program gets as far as startElement
    it never gets beyond the condition
    if (localName.equals("field")) {
    Can someone tell me why? Im not an experienced programmer.
    Thanks in advance.

    I based my program on this program:
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import org.apache.xerces.parsers.SAXParser;
    public class Flour extends DefaultHandler {
    float amount = 0;
    public void startElement(String namespaceURI, String localName,
    String qName, Attributes atts) {
    if (namespaceURI.equals("http://recipes.org") && localName.equals("ingredient")) {
    String n = atts.getValue("","name");
    if (n.equals("flour")) {
    String a = atts.getValue("","amount"); // assume 'amount' exists
    amount = amount + Float.valueOf(a).floatValue();
    public static void main(String[] args) {
    Flour f = new Flour();
    SAXParser p = new SAXParser();
    p.setContentHandler(f);
    try { p.parse(args[0]); }
    catch (Exception e) {e.printStackTrace();}
    System.out.println(f.amount);
    which has as the data
    <?xml version="1.0" encoding="UTF-8" ?>
    <?dsd href="recipes.dsd"?>
    - <collection xmlns="http://recipes.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://recipes.org recipes.xsd">
    <description>Some recipes used in the XML tutorial.</description>
    - <recipe>
    <title>Beef Parmesan with Garlic Angel Hair Pasta</title>
    <ingredient name="beef cube steak" amount="1.5" unit="pound" />
    <ingredient name="onion, sliced into thin rings" amount="1" />
    <ingredient name="green bell pepper, sliced in rings" amount="1" />
    <ingredient name="Italian seasoned bread crumbs" amount="1" unit="cup" />
    <ingredient name="grated Parmesan cheese" amount="0.5" unit="cup" />
    <ingredient name="olive oil" amount="2" unit="tablespoon" />
    <ingredient name="spaghetti sauce" amount="1" unit="jar" />
    <ingredient name="shredded mozzarella cheese" amount="0.5" unit="cup" />
    <ingredient name="angel hair pasta" amount="12" unit="ounce" />
    <ingredient name="minced garlic" amount="2" unit="teaspoon" />
    <ingredient name="butter" amount="0.25" unit="cup" />
    - <preparation>
    <step>Preheat oven to 350 degrees F (175 degrees C).</step>
    <step>Cut cube steak into serving size pieces. Coat meat with the bread crumbs and parmesan cheese. Heat olive oil in a large frying pan, and saute 1 teaspoon of the garlic for 3 minutes. Quick fry (brown quickly on both sides) meat. Place meat in a casserole baking dish, slightly overlapping edges. Place onion rings and peppers on top of meat, and pour marinara sauce over all.</step>
    <step>Bake at 350 degrees F (175 degrees C) for 30 to 45 minutes, depending on the thickness of the meat. Sprinkle mozzarella over meat and leave in the oven till bubbly.</step>
    <step>Boil pasta al dente. Drain, and toss in butter and 1 teaspoon garlic. For a stronger garlic taste, season with garlic powder. Top with grated parmesan and parsley for color. Serve meat and sauce atop a mound of pasta!</step>
    </preparation>
    my program doesnt need to account for namespaces apart from that I cant see why this would work and my one not.

  • Problem with SAX parser - entity must finish with a semi-colon

    Hi,
    I'm pretty new to the complexities of using SAXParserFactory and its cousins of XMLReaderAdapter, HTMLBuilder, HTMLDocument, entity resolvers and the like, so wondered if perhaps someone could give me a hand with this problem.
    In a nutshell, my code is really nothing more than a glorified HTML parser - a web page editor, if you like. I read in an HTML file (only one that my software has created in the first place), parse it, then produce a Swing representation of the various tags I've parsed from the page and display this on a canvas. So, for instance, I would convert a simple <TABLE> of three rows and one column, via an HTMLTableElement, into a Swing JPanel containing three JLabels, suitably laid out.
    I then allow the user to amend the values of the various HTML attributes, and I then write the HTML representation back to the web page.
    It works reasonably well, albeit a bit heavy on resources. Here's a summary of the code for parsing an HTML file:
          htmlBuilder = new HTMLBuilder();
    parserFactory = SAXParserFactory.newInstance();
    parserFactory.setValidating(false);
    parserFactory.setNamespaceAware(true);
    FileInputStream fileInputStream = new FileInputStream(htmlFile);
    InputSource inputSource = new InputSource(fileInputStream);
    DoctypeChangerStream changer = new DoctypeChangerStream(inputSource.getByteStream());
    changer.setGenerator(
       new DoctypeGenerator()
          public Doctype generate(Doctype old)
             return new DoctypeImpl
             old.getRootElement(),
                              old.getPublicId(),
                              old.getSystemId(),
             old.getInternalSubset()
          resolver = new TSLLocalEntityResolver("-//W3C//DTD XHTML 1.0 Transitional//EN", "xhtml1-transitional.dtd");
          readerAdapter = new XMLReaderAdapter(parserFactory.newSAXParser().getXMLReader());
          readerAdapter.setDocumentHandler(htmlBuilder);
          readerAdapter.setEntityResolver(resolver);
          readerAdapter.parse(inputSource);
          htmlDocument = htmlBuilder.getHTMLDocument();
          htmlBody = (HTMLBodyElement)htmlDocument.getBody();
          traversal = (DocumentTraversal)htmlDocument;
          walker = traversal.createTreeWalker(htmlBody,NodeFilter.SHOW_ELEMENT, null, true);
          rootNode = new DefaultMutableTreeNode(new WidgetTreeRootNode(htmlFile));
          createNodes(walker); However, I'm having a problem parsing a piece of HTML for a streaming video widget. The key part of this HTML is as follows:
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                  id="client"
            width="100%"
            height="100%"
                  codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
                  <param name="movie" value="client.swf?user=lkcl&stream=stream2&streamtype=live&server=rtmp://192.168.250.206/oflaDemo" />
             etc....You will see that the <param> tag in the HTML has a value attribute which is a URL plus three URL parameters - looks absolutely standard, and in fact works absolutely correctly in a browser. However, when my readerAdapter.parse() method gets to this point, it throws an exception saying that there should be a semi-colon after the entity 'stream'. I can see whats happening - basically the SAXParser thinks that the ampersand marks the start of a new entity. When it finds '&stream' it expects it to finish with a semi-colon (e.g. much like and other such HTML characters). The only way I can get the parser past this point is to encode all the relevant ampersands to %26 -- but then the web page stops working ! Aaargh....
    Can someone explain what my options are for getting around this problem ? Some property I can set on the parser ? A different DTD ? Not to use SAX at all ? Override the parser's exception handler ? A completely different approach ?!
    Could you provide a simple example to explain what you mean ?
    Thanks in anticipation !

    You probably don't have the ampersands in your "value" attribute escaped properly. It should look like this:
    value="client.swf?user=lkcl&stream=...{code}
    Most HTML processors (i.e. browsers) will overlook that omission, because almost nobody does it right when they are generating HTML by hand, but XML processors won't.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Problem with sax parser

    Hello..
    I have the following problem. When I parse an xml document with blank spaces and numbers with decimals, its sometimes comes out as one string and sometimes as two, for example "First A" sometimes comes out as "First" and "A" and sometimes as "First A", which is how its stored in the xml file. Same with numbers like 19.20. Im enclosing a little of my code..
    public void characters(char buf[], int offset, int len)
    throws SAXException
    if (textBuffer != null) {
    SaveString = ""+textBuffer;
    if(i>-1)
    numbers = SaveString;
    Whats wrong and how do I fix it.
    Best Regards Dan
    PS I have more code, in data and out data if needed.Ds

    Hello,
    I do not know if this is your problem, yet please find hereafter an excerpt of the SAX API:
    public void characters(char[] ch,
                           int start,
                           int length)
                    throws SAXException
    ... SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks;...
    ... Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so)...
    In other words, I am afraid that your issue is the "standard behaviour" of a SAX parser.
    I hope it helps.

  • Problem Using Sax parser with Eclipse 3.0 and command line

    Hi,
    I am parsing a xml file with sax. When I am running my programm in the command line everthing is ok and I get the right results from parsing.
    But if I am running the programm in Eclipse 3.0 (the same java code) I get an other result (the wrong results).
    Does anybody know what this can be the reason for. Is Eclipse using an other xml parser and if where I can change the parser?
    It would be very kind if somebody can give me a reason for this strange behaviour.
    Thanks in advance

    I have solved my problem.
    In the command line I used jre 1.4 and in Eclipse I used jre 1.5.
    I think jre 1.5 uses an other xml parser so I got an other result.
    If i use in Eclipse jre1.4 I get the same result as in the command line.

  • SAX parser problem in JDK1.5

    I have parse the xml file using SAX in jdk1.5 environment. During the parsing, it missed the some text content.
    for example
    <employeeid>
    <empid>1001</empid>
    <empid>1002</empid>
    </employeeid>
    If i have parse the above xml file using SAX in jdk1.5 environment. The output is
    1001
    100
    during the parsing , SAX parser misses digit of 2.
    if i have parse the above xml file using SAX in jdk1.4 environment , it is working fine.
    what is the problem in jdk1.5
    please help
    bala

    What I expect the problem to be was discussed recently in a topic titled "SAX Parser Problems" that was started on March 14 at 6:59 AM by JackoBS.
    Read that and see if it fixes your problem. If so, it is not a JDK1.5 problem, but a user error.
    Dave Patterson

Maybe you are looking for

  • How to get custom field name and value in data table using csom

    i am using using this code but iam not getting FieldValues property..  internal void ReadProjectCustomFields(string strProjectName)             string url = "https://techwhizepm.sharepoint.com/sites/rnd/";             using (ProjectContext projContex

  • FM to rename attribute like se80

    HI All What is the FM that i can use fpr  rename object like in se80 when you try to rename class you get in first row the old name and in the second row you have the new name that you want to change Regards Alex

  • Computer HD crash

    My computer HD crashed with no backup. I have 56GB worth of music on my iPod. I had a new HD installed and everything is working fine except I can't figure out how to copy my music from my IPod to iTunes on the new HD so I can start sync'ing again. T

  • Applying a texture to a triangle - and have the texture shrink/scale

    I'm hoping to find a way to apply a texture to an arbitrary triangle while having the texture scale to fit inside the triangle. Imagine taking an Image (the texture) and defining three points (a,b, and c). Then imagine creating Polygon where you defi

  • 6810 PC Suite 6.84.10.4 - USB Device not recognise...

    After some years of synchronising correctly with my PC suddenly for no apparent reason PC suite stopped working, and gives the message:- "One of the USB devices attached to this computer has malfunctioned...." I am using a CA-53 cable connecting to a