Characters(char,int,int) problem ???

Hello, I'm using SAX to parse an XML file, but i run into a problem with the characters() method (well that's what I think). I use it to get the contents of text nodes, but sometimes (actually, only once) it will return only half of the text. But, you will tell me, this should be normal since the parser is allowed to call it twice in a row.
But I create a StringBuffer myStringBuffer, then in characters(char[] buffer,int offset,int length) i do myStringBuffer.append(buffer,offset,length) and in endElement i try to process myStringBuffer, but still it contains only half of the text. This is all the more strange to me that my XML file is full of text nodes much longer than the troublesome one and i have no problem with those...and when i extract this s***** node and put it into another XML file, it works fine.
So I'm somehow confused.
Thanks in advance.

Your logic certainly looks like it should work, but obviously it doesn't. Here's what I do:
1. In the startElement() method, create an empty StringBuffer.
2. In the characters() method, append the characters to it. Incidentally you don't need to create a String like you do, there's an "append(char[] str, int offset, int len)" method in StringBuffer which is very convenient in this case.
3. In the endElement() method, use the contents of the StringBuffer.
As for why parsers split text nodes, don't try to second-guess that. It's not your business as a user of the SAX parser. Some parsers will read the XML in blocks, and if a block happens to end in the middle of a text node, it splits the text node there. Others will see the escape "&" in a text node and split the node into three parts, the part before the escape, a single "&" character, and the part after it. Saves on string manipulation, you see. There could be other reasons, too.

Similar Messages

  • Question about public void characters(char []ch, int start, int length) thr

    Can anyone tell me how you would keep all the characters from within one pair of tags together each time characters() is called?
    the character() method doesn't read all the character data at once, and i would like to create a buffer of what it has read.
    thank you.

    I recommend using getNodeName and/or/combination
    with
    getNodeValue to get the strings.i have tried using a buffer, and i have got that to work!
    At long last I am seeing the string I would like to see as it is in the xml file!
    thank you for your help
    here is an example of my code:
    private boolean isDescription = false;
    StringBuffer sb = new StringBuffer();
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         if(localName.equals("description")) {
              sb = new StringBuffer();
              isDescription = true;
    public void characters(char []ch, int start, int length) throws SAXException {
         if(isDescription == true) {
              String desc = new String(ch, start, length);
              sb.append(desc);
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
         if(localName.equals("description")) {
              isDescription == false;
              System.out.println(sb.toString());
    }

  • Unsigned int - problem translating c++ function to java

    OK so here's the deal:
    I'm writing a client for a internet comunicator in java (J2ME to be precise). Unfortunately i have specs for this comunicator's protocol for c++ programing. The first problem I ran to is: I have to calculate a hash for a password so it doesn't go plain text on the network. The function in c++ that does this is:
    int getPasswordHash(char *password, int seed){
        unsigned int x=0, y=0, z=0;
        char *pwd = password;
        y = seed;
        for (x = 0; *password; password++) {
         x = (x & 0xffffff00) | *password;
         y ^= x;
         y += x;
         x <<= 8;
         y ^= x;
         x <<= 8;
         y -= x;
         x <<= 8;
         y ^= x;
         z = y & 0x1f;
         y = (y << z) | (y >> (32 - z));
        cout << "Hash for \"" << pwd << "\" with seed \"" << seed << "\": " << y << "\n";
        return y;
    }My translation to java goes:
    public int getPasswordHash(String password, int seed){
        long x = 0, y = 0, z = 0;
        int tmp = 0;
        String pwd = password;
        y = seed;
        for (x = 0; x < password.length(); x++){
            tmp = (int)x;
            x = x | password.charAt(tmp);
            y ^= x;
            y = uintadd(y, x);
            x <<= 8;
            y ^= x;
            x <<= 8;
            y = uintsubst(y, x);
            x <<= 8;
            y ^= x;
            z = y & 0x1f;
            y = (y << z) | (y >> (32 - z));
            x = tmp;
        System.out.println("Hash for \""+ pwd + "\" with seed \"" + seed + "\": " + y);
        return (int)y;
    public long uintadd (long x, long y){
        long xL = x & 0xffffffffL;
        long yL = y & 0xffffffffL;
        long sumL = xL + yL;
        long sum = (sumL & 0xffffffffL);
        return sum;
    public long uintsubst (long x, long y){
        long xL = x & 0xffffffffL;
        long yL = y & 0xffffffffL;
        long sumL = xL - yL;
        long sum = (sumL & 0xffffffffL);
        return sum;
    }So I use the uintadd and uintsubst to add and substract values that should be unsigned int. Every operation works exactly like in c++ (I've checked) until this point:y = (y << z) | (y >> (32 - z));and to be exact (y << z) This doesn't turn out like in c++ so the whole function doesn't return the right vaule. I know it's because doing a bit operation on a unsigned int in c++ is different in than in java because unsigned variables have totally different bit values than signed ones. The question is: how to work this out. I managed to do aritmetic operations working but I have no idea how to deal with this. Any help would be great.

    I'm by no means the expert with this, but I'm going
    to guess that this would work...
    y = ((y << z) & 0xffffffffL) | (y >> (32 - z));
    thus... to zero out the right shifted 1's before the
    orWOW WOW WOW it totaly works thanks alot bsampieri !!

  • Char int and println MeSS, help plz any1??

    Hello dear people.
    Well, homework assignment was to write a code which will output the alphabet parallel a-z , A-Z
    using a for-loop
    so.... her's what i wrote:
    public class buha {
         public static void main(String[] args) {
              for (int nm=65; nm==90; nm+=1){ //A=65, Z=90, this is a numerical
                                             //presentation of the alphabet
                   char g=(char)nm;           //g for the capital letters
                            char k=(char)(nm+32);     //k for the small letters, 32 is
                                            //the difference between small and capital
                             System.out.println(g, ' ', k); //this show output capital, few spaces
                                            //and small.
    }Why isn't it working?
    Compiler shows an error with the println
    thanks allot, Amit

    thank you for your posts.
    i fixed the code as Sabre offeres (is the second expression in a for loop functions as a while condition or as an end condition?)
    now it looks like that:
    public class buha {
         public static void main(String[] args) {
              for (int nm=65; nm<=90; nm+=1){ //A=65, Z=90, this is a numerical
                                             //presentation of the alphabet
                   char g=(char)nm;           //g for the capital letters
                            char k=(char)(nm+32);     //k for the small letters, 32 is
                                            //the difference between small and capital
                             System.out.println(g, "  " , k); //this show output capital, few spaces
                                            //and small.
    }and still showing the same problem about the println, namely:
    The method println(char) in the type PrintStream is not applicable for the arguments (char, String, char)
    ideas?

  • Int[][][][][][][][] problem

    All through vector can solve such problem.but this time, I will use array because there are some null value. and using vectors will lost the positions.
    I can do int[][][][][][] a=new int[][][][][]. create it, initial it and print it.
    but how can create a none certain int array. say it may be int[], or int[][], or int[][][].
    Are there any command say:
    int{7}=int[9][9][9][9][9][9][9];
    or if it's not possible. but that's just syntax problem. how can create a int[][][][][][] in this way:
    int[]a=new int[];
    int[]b=new int[];
    int[]a[0]=b;
    but i can not do that.
    any help?

    Please avoid cross-posting the same question into different forums in the future. I have answered your question at:
    http://forum.java.sun.com/thread.jsp?forum=54&thread=189313

  • Int problem still?

    I am trying to convert an Integer to int and I figured out the .intValue()........thanks to some of you, but my problem isn't totally solved?????
    I am getting an error saying " missing term" now!
    The following is exactly what I am trying to do, I take in a date as 3/12/2002, and I am using string tokenizer to divide this up into day month and year! I then want to be able to assign these int values to the function calA:
    Calendar calA = Calendar.getInstance();
    int std = 0;
    int stm = 0;
    int sty = 0;
    StringTokenizer st = new StringTokenizer(StartDate, "/");
    Integer stday = new Integer((String)st.nextElement());
    Integer stmonth= new Integer((String)st.nextElement());
    Integer styear = new Integer((String)st.nextElement());
    std = stday.intValue();
    stm = stmonth.intValue()-1;
    sty = styear.intValue();
    calA.set(stm,std,sty);
    Can you PLEASE HELP :) I am desperate!

    To parse a date, you'd better use java.text.SimpleDateFormat instead of trying to do it yourself with a StringTokenizer.
    String startDate = "3/12/2002";
    // I guess you have a date with format month/day/year
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    // Parse into a Date object
    Date date = df.parse(startDate);
    // Set the calendar
    Calendar calA = Calendar.getInstance();
    calA.setTime(date);Jesper

  • Char[int i]

    Hi,
    Please let me know whether declaring a char array of dynamic size is allowed or not.
    e.g.,
    int i = 25;
    "char[ i ] c";
    Thanks
    Ajay

    typo there: "compiler doesn't like you" should read "compiler doesn't like it (your code)";-) /u/jos/java:115>javac -cp . com/company/project/*.java
    javac: doesn't like j.a.horsmeier; refused to compile his code at line 1
    exit status: 1
    /u/jos/java:116>
    Shudder, what a nightmare it'd be ;-)
    kind regards,
    Jos

  • Character.digit(char, int) doesn't know the diff of 'a' and 'A'

    I did Character.digit('a', 16) and Character.digit('A', 16), and they both gave me 10. Is there a function that can decipher between capitals and lowercase.
    I am trying to create a random sequence of characters...and I can't seem to figure out a good method to do this. I think the method Character.digit(char, radix) isn't the best of methods.

    No! That is not the right method to use. You should have seen the API before posting your explanation.
    Anyway, you could try this,
    import java.util.Random;
    Random r = new Random();
    char upch = 'A' + r.nextInt(25); // for next random upper case letter
    char lowch = 'a' + r.nextInt(25); // for next random lower case letterI assume that, by characters in your question, you meant English alphabet.
    HTH

  • Reading int problem

    Hi there, I am writing a client server program in which I get two integers in client and then I have to send them to the server. I have sent the integers in client as follows:
    outToServer.writeInt(x); // where outToServer is the DataOutputStream object reference
    outToServer.writeInt(y);
    But when I try read at server as follows:
    int clientx = inFromClient.read();
    and when I do :
    System.out.println("clientx = "+ clientx);
    I get clientx = 0; instead of a specific number.
    Am I doing the right thing by using read() or is there any other way I can read an integer from the BufferedReader?

    DataInput/OutputStream must be used symmetrically. That means that if you write with writeInt, you must read with readInt, not Reader.read(). If you actually read the documentation for Reader.read(), you'll see it "reads one character from the input stream". That's obviously not what you want!
    Lesson, use it symmetrically! If you're writing with a DataOutputStream, read with a DataInputStream.

  • 2960S management int problem

    I have a stack of 2 2960S switches that are dedicated for the storage net, only between SAN and blade system.
    I have configured fastethernet0 (management interface) for static ip 192.168.163.25 which is then connected to my core data switch, so i can manage the storage switch.
    So here is the issue: if there is nothing connected to that stack at all, except the management int the switch pings and i can telnet to it.
    However, if i boot the stack with all storage network uplinks and downlinks connected the management int does not ping and i have no access to the switch. As soon as i unplug the last cable, the management interface starts to ping and i can telnet in. Then i can plug all the cables and everything works fine, until i reboot the switch again.
    Anybody have any ideas whats going on?
    I can paste the config if needed.

    I understand that, and do not want to use it as a data carrying port.
    All i want to do it to use it for telnet, mgmt, but i can't because it doesn't ping after the switch boots up if i have the rest of the data cables plugged it.
    Below is the config:
    ! Last configuration change at 09:51:19 Central Tue Jun 1 2010
    ! NVRAM config last updated at 10:22:06 Central Tue Jun 1 2010
    version 12.2
    no service pad
    service timestamps debug datetime msec
    service timestamps log datetime msec
    no service password-encryption
    hostname BEP-2960-SAN1
    boot-start-marker
    boot-end-marker
    enable secret
    enable password
    no aaa new-model
    clock timezone CST -6
    clock summer-time Central recurring
    switch 1 provision ws-c2960s-24td-l
    switch 2 provision ws-c2960s-24td-l
    authentication mac-move permit
    ip subnet-zero
    no ip source-route
    no ip gratuitous-arps
    ip domain-list
    ip domain-list
    ip domain-name
    vtp mode transparent
    spanning-tree mode pvst
    spanning-tree etherchannel guard misconfig
    spanning-tree extend system-id
    vlan internal allocation policy ascending
    vlan 10
    name Storage
    vlan 11
    name VMotion
    interface Port-channel1
    description Etherchannel to ESXi PROD1
    switchport trunk allowed vlan 10,11
    switchport mode trunk
    switchport nonegotiate
    flowcontrol receive desired
    interface Port-channel2
    description Etherchannel to ESXi PROD2
    switchport trunk allowed vlan 10,11
    switchport mode trunk
    switchport nonegotiate
    flowcontrol receive desired
    interface FastEthernet0
    description Management
    ip address 192.168.163.25 255.255.255.0
    interface GigabitEthernet1/0/1
    description Connection to ESXi PROD1
    switchport trunk allowed vlan 10,11
    switchport mode trunk
    switchport nonegotiate
    speed 1000
    duplex full
    flowcontrol receive desired
    spanning-tree portfast trunk
    channel-group 1 mode on
    interface GigabitEthernet1/0/2
    description Connection to ESXi PROD2
    switchport trunk allowed vlan 10,11
    switchport mode trunk
    switchport nonegotiate
    speed 1000
    duplex full
    flowcontrol receive desired
    spanning-tree portfast trunk
    channel-group 2 mode on
    interface GigabitEthernet1/0/3
    interface GigabitEthernet1/0/24
    description Connection to BEP-FAS-02 1G
    switchport access vlan 10
    switchport mode access
    flowcontrol receive desired
    spanning-tree portfast
    interface GigabitEthernet1/0/25
    shutdown
    interface GigabitEthernet1/0/26
    shutdown
    interface TenGigabitEthernet1/0/1
    description Connection to BEP-FAS-01 10G
    switchport access vlan 10
    switchport mode access
    flowcontrol receive desired
    spanning-tree portfast
    interface TenGigabitEthernet1/0/2
    interface GigabitEthernet2/0/1
    description Connection to ESXi PROD1
    switchport trunk allowed vlan 10,11
    switchport mode trunk
    switchport nonegotiate
    speed 1000
    duplex full
    flowcontrol receive desired
    spanning-tree portfast trunk
    channel-group 1 mode on
    interface GigabitEthernet2/0/2
    description Connection to ESXi PROD2
    switchport trunk allowed vlan 10,11
    switchport mode trunk
    switchport nonegotiate
    speed 1000
    duplex full
    flowcontrol receive desired
    spanning-tree portfast trunk
    channel-group 2 mode on
    interface GigabitEthernet2/0/3
    interface GigabitEthernet2/0/24
    description Connection to BEP-FAS-01 1G
    switchport access vlan 10
    switchport mode access
    flowcontrol receive desired
    spanning-tree portfast
    interface GigabitEthernet2/0/25
    interface GigabitEthernet2/0/26
    interface TenGigabitEthernet2/0/1
    description Connection to BEP-FAS-02 10G
    switchport access vlan 10
    switchport mode access
    flowcontrol receive desired
    spanning-tree portfast
    interface TenGigabitEthernet2/0/2
    interface Vlan1
    no ip address
    shutdown
    interface Vlan10
    description Storage
    ip address 192.168.10.1 255.255.255.0
    interface Vlan11
    description VMotion
    ip address 192.168.11.1 255.255.255.0
    ip http server
    ip http secure-server
    ip sla enable reaction-alerts
    snmp-server community read RO
    snmp-server community write RW
    ntp clock-period 22518825
    ntp server 192.168.168.2 key 0 prefer
    end

  • Free Chars int the Planning Layout

    Hello IP gurus,
    Is it advisable to put too many free characteristics in the planning layout and in the real time cube . My user is requesting too many chars in the layout and I am suggesting to have it in the report/reporting cube and not in the layout/real time cube. All are actual and nothing to do with planning chars/key figures. Can you please advice what is the best design. Thanks in advance for your help guys.
    Senthil

    Hi,
    You can use free characteristic ,if you are going to plan at that granularity.For input ready query used in planning ,characteristics
    part of aggregation level has to be part of row or column.So check at what granularity you are going to plan for data,then decide design.
    Regards,
    Indu

  • CreateImage(int, int) problem -- or..?

    I'm trying to get a program double buffered, and have followed the structure for doing so provided by Sun. However, the program does not work correctly.
    Problem #1: I have to "manually" refresh the JFrame (put it behind a window, then bring it back to the foreground), and everything seems to work correctly.
    Problem #2: When the program first starts, I get 2 NPE's.
    Note: Both of these problems usually occur. Rarely, the entire thing runs perfectly with no problems at all.
    Here is how the code is structured:
    Graphics offScreen;
    Image offScreenImage;
    public void paint(Graphics screen)
    update(screen);
    public void update(Graphics toPaint)
    if( offScreenImage == null )
    offScreenImage = createImage(640, 480);     
    offScreen = offScreenImage.getGraphics();
    setBackground(Color.gray);          
    board.draw(offScreen);
    toPaint.drawImage(offScreenImage, 0, 0, null);     
    } //end draw()
    Also, the draw(Graphics) method from the board instance is:
    public void draw(Graphics offScreen)
    offScreen.drawImage(testImage, 25, 25, null);
    What could be causing these problems? Is there anything special that needs to be done if I'm using separate object files to draw? The NPE's are always flagged at this line:
         board.draw(offScreen);
    Any suggestions would be GREATLY appreciated.

    problem #1: Try moving the initializing code from update to paint or make paint to call update. Paint is the method that is called first to paint the component, update is called to repaint it.
    problem #2: "board.draw(offScreen);" can cause a NPE if a) board is null or b) offScreen is null. Which one is it?
    Also, in swing you should override the paintComponent-method instead of paint. (And aren't swing components double buffered by default? I'm not sure about that...)

  • MSI 651M Combo-L Video Int problems

    I have install at MSI 651M Combo-L Windows XP prof+SP1 (Windows 2000 prof+SP3/SP4). After install Video drivers for intergration video, my system is abend with error 0x7F. With using Windows 98 - video is installation and work - good. My BIOS - 1.3, Video Drivers - Driver version: Win2K/XP: 6.14.10.2170.
    Please help.

    a marginal psu may be?
    http://www.memtest86.com on ram

  • [SOLVED] Non english chars kdemod 4 problem

    Hello, I have a little problem with KDE and the non english charactes.
    If I open a file with non english chars in its name I get something like this:
    (In this case kwrite opens "other" file but in other applications it fails with an error of file not found)
    Other sympton is that in KDE menu my name have bad chars too:
    (It must be López)
    And the third sympton is that if try to rename a file in the desktop, I can't write accented chars (á é í ó ú). At the begining the keyboard in this rename dialog was totally in english but i have got a semi spanish keyboard (i can write ñ letters) with the apropiate /etc/hal/fdi/policy/10-keymap.fdi file.
    But the most strange is that in general, in all Kde and non-kde applications and even in the console, non english chars works ok. I can go to the file->Open menu of the application and open a file with non english chars in its name. The problem seems to reside in the part of kde that passes the name of the file to the application (¿kwin?)
    my locale is es_ES@UTF8 and as I said I have configured correctly the 10-keymap.fdi file.
    I have read in some forums that something like this could be a kde or qt bug, but for me it's not clear as i don't see a general complaining about this.
    Any idea will be apreciated.
    Thanks in advance,
    Christian.
    Last edited by christian (2009-03-27 14:52:17)

    SanskritFritz wrote:
    That should be "es_ES.utf8"
    Sorry, i mispelled it in the post.
    Of course, my locale is es_ES.utf8:
    LANG=es_ES.utf8
    LC_CTYPE="es_ES.utf8"
    LC_NUMERIC="es_ES.utf8"
    LC_TIME="es_ES.utf8"
    LC_COLLATE=C
    LC_MONETARY="es_ES.utf8"
    LC_MESSAGES="es_ES.utf8"
    LC_PAPER="es_ES.utf8"
    LC_NAME="es_ES.utf8"
    LC_ADDRESS="es_ES.utf8"
    LC_TELEPHONE="es_ES.utf8"
    LC_MEASUREMENT="es_ES.utf8"
    LC_IDENTIFICATION="es_ES.utf8"
    LC_ALL=
    I don't think this could be the source of the problem, because, except in the places I said in the firs post, the rest of my system works perfectly.

  • Special characters like hyphens cause problems in Text to Speech on Mac

    The Text to Speech function with the shortcut [option+esc] has helped me  a lot. But, the only problem is that when there is a hyphen in the paragraph selected it doesn't even start reading the paragraph.
    This problem occurs when reading pdf files from the chrome using TTS.

    I thought that perhaps that I might be able to do something like make the iPod screen have a white text on black mode (like in the Mac OS X accessability mode), would this be possible?
    Can anyone else think of anything when using an iPod to help vision impaired people to use an iPod?
    Cheers,
    Nicholas

Maybe you are looking for

  • My ipod touch will sync music but when i go to play it it will not play.It goes from the play screen back to menu

    Help! my ipod touch will sync music and podcasts. They show up on the playlists but when I tap on them to play it very briefly show the artist/album cover for playing but then quickly reverts to the playlist or artist menu. I have restored it and tri

  • How to give save as dialog box using servlet?

    hello, i am building one application where i am generatinfreport in excel format. now the file generated is output.xsl. this is in c:\bea\wlserver6.1 directory. now i want to write a servelt get this file from location given above and give user Save

  • Accessing a class outside the package

    Hi friends ! Suppose I have a class called InsidePackageClass which is placed under C:\Package and other called OutsidePackageClass that is placed directly under C: Suppose my classpath points to C:\ and I want to declare a OutsidePackageClass member

  • Error -creating Recurring Invoice-R12, Version 12.1.1.

    Hi, When I am creating the Recurring invoice in accounts Payable( R12, Version 12.1.1.) I got the following error message "APP-SQLAP-10000: ORA-04062: signature of package "APPS.AP_ETAX_PKG" has been changed occurred in Get_Quote<-Calculate_Tax<-Post

  • Hashtable mapping question

    Hello All: I have a hashtable object in my java code thats represented as a jobject in my jni code. I then call GetObjectClass to get the class for this jobject. Finally I call GetMethodID to retrieve the method ID for the put method of the hashtable