Byte position of single character

Hi,
I am dealing with very big XML files and since I don't need all the information in them, I would like to have random access to the XML elements, to pick the ones I am interested in (without loading/searching the whole document every time).
So, I wanted to create a index of the XML file with xpath expressions (from the root to the element of interest) as keys and byte positions as values. I would need to parse the XML only once and record the byte position at the beginning of the start tag and at the end of the end tag. Thus if I read from the start position to the corresponding end position in the file, I would end up with proper xml that is only the part of the file that I am interested in.
E.g.: Once I have the index I could use RandomAccessFile to retrieve a byte array from start to stop position and convert it to a String using the correct encoding.
BUT: I haven't found a way to get to the needed byte position.
I tried using XMLStreamReader, since it has a method getLocation, but I have problems with that too.
( see: http://forum.java.sun.com/thread.jspa?threadID=5198055 )
And if I use a reader like InputStreamReader, I would be able to read character by character and parse the file myself, but I don't get the byte position (even using CountingInputStream, since the reader buffers the input stream).
Any ideas how to tackle this problem, hints or alternatives are highly appreciated!
Thanks!

Do you mean "how many characters before the last newline", or "how many bytes before the last non-\n (possibly also non-\r) byte", or "what is the byte position of the first byte of the last character", or something else? Those can be different things if you have a multibyte encoding.
For last byte (or ISO-8859 character): get length of file (see File javadoc), seek and read using RandomAccessFile until you find something you don't consider newline (you need to think about carriage return vs linefeed.)

Similar Messages

  • I cannot select a single character

    I'm running Pages 5.2.2 on MacOS 10.9.4 on a 2011 MacBook Pro. The problem is I cannot select a single character with my Magic Mouse. If I try to drag over a single letter to select it, the cursor is positioned either before or after the letter. I can select and format groups of two or more characters, but not just one. It works with the trackpad though. I can select single characters with the mouse in other apps such as Word.

    While we all have MacBooks in this forum most of us don’t run Mountain Lion. There's a Mountain Lion Support Community where everybody has Mountain Lion. You should also post this question there to increase your chances of getting an answer. https://discussions.apple.com/community/mac_os/os_x_mountain_lion

  • Serial communication to read single character

    Hi! List,
    I want to read single character using serial communication(see the attached VI).
    The initialization of the serial port is taken care.
    TIA
    Attachments:
    Serial_comm[2_read_single_character].vi ‏42 KB

    I'm not sure I can understand you. If you want to read just one single character why can't you do so by just passing 1 to the Serial Read function as the number of bytes to read?
    The diagram of above VI doesn't make to much sense to me I have to admit.
    Rolf K
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Typing in s single character in an email address results in many...

    I have this strange problem when I attempt to type in an email address in an email, or I try to add an email address to an address book contact. As I type a single character I will get multiple characters typed for that single keystroke, (i.e., if I type "k" I will get "klstp". and if I attempt to backspace, f4, or any key, it will continually apply the same "klstp" for that instance.) This behavior will go away and reappear at no known pattern or time. One thing that is additionally wierd is the characters that will show up are always characters that are contained in that persons email address or somewhere in their address book listing.
    Some of the troubleshooting I have already attempted to do is use another keyboard, run Onyx utility to repair the system, but nothing seems to work.

    Thanks for your suggestion, but I understand the previous recipients function that you are speaking of. This is not that. This is random character sets that show with a single character being typed, but it is not any combination that exists from previous recipients. As an example if I type the letter S, I will get the letters SDQT, if I then hit backspace to remove it it will again type SDQT, if I then use an arrow key to try and move the position of the curser, it will again type SDQT. The only key I have found that will not do this is the ESC key. The important part here is that the combination SDQT is not part of an email address anywhere in my address book or previous recipients, and this combination of characters is only an example, the actual characters appear to be random.

  • Is it possible to horizontally reverse a single character in a text box containing other text?

    I have a client that wants every subhead to begin with a backward character throughout the entire book. 21 chapters, roughly 4 - 5 subheadings per chapter - the reversed character will always be an R in the same font. I don't know if there's a style setting I'm overlooking, but I would very much like to be able to define it as a character style. Much thanks in advance to anyone posting useful information!

    I don't think it's possible to reverse just one character, but here is an interesting work-around. From jongware, (a frequent and helpful poster here), a script demo that you can use to make a single character font.
    Download the One-Character Demo from http://www.jongware.com/binaries/indyfont_demo.zip, unpack and copy it into your User Scripts folder. Run the script once to set up a font template, draw your custom character -- the default is a bullet --, then run the script again to convert it to an OpenType font.
    You would need to flip your letter R and convert it to outlines, then use the script to make it into a one-character font. You cant then set your subhead style to have bulleted (with your reverse R defined as the bullet).

  • How do I control read start position in a very large file where start byte position may be larger than I32 (+/- 2^31)?

    Using LabView, I am trying to read a very large file which may be on the order of 2^32 bytes. I need to be able to step into the file at a byte position which may be greater than the I32 limit set by the read file.vi. Are there any options to the read file.vi or a method of circumventing this limitation?

    I'm not sure but i think that you can manage the "pos mode" in the "seek" sub-vi.
    The "pos mode" let you choose the initial position to add the numbers of bytes you want to move.
    I think that you can add a i32 number from the "initial" in the "pos mode" an latter use the "pos mode" in "current" to add another value. Then the next time you can move more than 2^31 bytes to the initial position.
    I hope you understand my idea, i wasn't try it before, but i think that would work.

  • LSMW SEL_DATE filed Single - Character Flag

    Dear gurus
    i created a lsmw for T/code VK12 . I faced problem when the LSMW read till convert data.
    In the VK12 , this Screen Field SEL_DATE will be my valid on date. I created the source filed Valid on date to match the mapping with SEL_DATE.
    Here are my example of data:
    SEL_DATE : 12022009
    VALID_ON : 12022009 ( read from my text file)
    the recording , mappings and source fields are created perfectly. Even read data display , the record able to shows out accordingly. But when comes to convert data , SEL_DATE return to me 1 Field Length.
    Now i feel so puzzled, why this happen?
    After some checking find out that this particular field SEL_DATE is a "SINGLE-CHARACTER FLAG"
    expert out there, do you have any suggestions or guidance? i really need this field as to identify my record.
    Without valid on date i can't call out the specific record and update it using LSMW
    thanks
    Wilson Low

    HI all,
    I recently have the same problem. With the help of other forum post, I was able to solve this problem in this way:
    1. Export the lsmw project (Extras->Export Projects) to a file.
    2. Edit the exported file and search for SEL_DATE field. Edit the last column in the right and change:
    000001000002000001CHARC to 000001000002000010CHARC
    3. Import the project using the modified file (Extras->Import Projects).
    Problem solved.
    Cheers.

  • How to copy a single character on a Q10?

    Hello forum,
    To copy text on my Q10 one needs to select a text and tap on it for a few seconds in order to get the copy icon available. However, when I want to copy a single character it doens't work because the OS thinks I'm hitting the balloon/arrow either in front or behind the selected character.
    Since there are no keyboard shortcuts for copy-pasting in OS10 I wonder how I should get this done (and I mean, just straight forward copying a single character, not a workaround)
    Thanks

    I have big fat fingers, and I didn't tap it, just touch that selected area for a second and release.
    It works.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How do I delete or edit a captured text layer that contains a single character in Cp 5?

    My captured text layer contains a single character '7'. This renders immediately when I publish the movie, but I don't get any options when I try to edit the layer by right-clicking on it.
    Can anyone help as this is very annoying...

    Hello,
    Welcome on the forum.
    Since you are talking about 'capture', I presume you are pointing to a Typing object? You cannot edit this right away. Depending on what you want to realize, could propose two workarounds:
    If you only want to show something typing (demonstration - but another text than your character), replace the Typing object by a Text Animation (right-click menu), you'll be able to edit it.
    If you want the user to type in a text, delete the Typing object and replace it by a Text Entry Box.
    Lilybiri

  • How to pass a single character to dll (as a parameter)

    How do pass a single character to dll (as a parameter). This is a third party dll that i am unable to change.
    e.g.: int functionName(char* process, char myChar);

    My apoligies, I am trying to pass a char from Teststand. Passing as a char is not one of the Category
     I tried sending (for example) : Locals.myChar[0].  Which is acceptable in C++, but gives me an error via Teststand.

  • GREP to find single character

    I put together a GREP style inside of a paragraph style that is supposed to find all instances in the paragraph where there is one single character inside of parethesis. This is what I typed in:
    (?<=\().(?-\))
    and I assigned a character style that is supposed to change the character inside the parenthesis, but not the parenthesis themselves.
    But it's not working. Can anyone help me with how to fix it?

    For any other readers greppling with same,
    (?<=\().(?=\))
    [Breakdown:
    (?<=x) Lookbehind string x
    \(  .. which is an open parenthesis -- escaped, because it's a GREP special character
    .  Any character. Any at all! Imagine that!
    (?=y) Lookahead string y
    \)  .. which is a closing parenthesis -- see above]

  • Textarea - create String that acts like a single character

    Hi guys,
    I am trying to create a string in a textarea that acts like a single character. By this, I mean that the user cannot edit the contents of that section of text. Here's an example:
    Textarea text:
    [Number of Iterations] * 35 / 200
    I want the [Number of Iterations] to be read-only. In addition, if the user tries to delete the beginning or end of [Number of Iterations], the whole thing is deleted. If possible, I would like cursor operations to treat it like a single character as well (i.e. to go from |[Number of Iterations] to [Number of Iterations]| takes a single right button press).
    Some commercial applications like Microsoft Word do this with Automatically created text in documents (like page numbers and date stamps) and I was wondering if I could do the same thing using a Textarea.
    Any help would be greatly appreciated.
    Thanks in advance,
    Steve

    A JTextPane allows you to add components to the text pane. So you might be able to create a JLabel with your desired text and insert the label into the text pane.

  • InDesign CS4: change position of single column guides using numerical input?

    We can change the position of single column guides to obtain unequal columns. We simply drag the guides. But is it possible to do this more precisely, hence using a numerical input field?
    To obtain the same result, I currently create a smart guide and then align the column guide with the smart guide. This is OK, but an input field for the column guide would be quicker.
    If there is currently no better way than mine, then understand this "numerical input field for column guides" as suggestion please.
    Thanks, Michael

    We can change the position of single column guides to obtain unequal columns. We simply drag the guides. But is it possible to do this more precisely, hence using a numerical input field?
    To obtain the same result, I currently create a smart guide and then align the column guide with the smart guide. This is OK, but an input field for the column guide would be quicker.
    If there is currently no better way than mine, then understand this "numerical input field for column guides" as suggestion please.
    Thanks, Michael

  • How to make a filter in a table while giving single character

    hi,
    i have doubt in filter how to make a filter while giving single character in a table during runtime.
       if i give string like(A*) means then how it can retrive the data from the table

    look at:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/60d5b593-ba83-2910-28a9-a7a7c7f5996f

  • Replace multiple characters to single character

    Hi friends,
    I would like to replace multiple characters in a string to a single character. The character may be a pipe (|) or a tilde (~).
    For example "|||asdf||123|xyz||" should be changed to "asdf|123|xyz".
    I use Oracle 11g2.
    Thanks in advance!

    Without regexp
    with testdata as (
        select '||asdf||||123|xyz|' str from dual union all
        select 'asdf|123|||||||xyz||||' from dual union all
        select '||||||asdf|||123||||||xyz||||||' from dual
    select
    trim (both '|' from
        replace (
            replace (
                replace (str,'|','|'||chr(0))
                ,chr(0)||'|'
            ,chr(0)
    ) str
    from testdata
    STR
    "asdf|123|xyz"
    "asdf|123|xyz"
    "asdf|123|xyz"
    with regexp
    with testdata as (
        select '||asdf||||123|xyz|' str from dual union all
        select 'asdf|123|||||||xyz||||' from dual union all
        select '||||||asdf|||123||||||xyz||||||' from dual
    select
    trim (both '|' from
        regexp_replace (
            str
            ,'\|+'
            ,'|'
    ) str
    from testdata
    STR
    "asdf|123|xyz"
    "asdf|123|xyz"
    "asdf|123|xyz"
    Message was edited by: chris227 regexp added

Maybe you are looking for

  • Safari Crash sometimes on flash movies

    Hello Safari regularly crashes Safari I open several page or when i read Flash. Here is a part of my crash report; Process: Safari [2151] Path: /Applications/Safari.app/Contents/MacOS/Safari Identifier: com.apple.Safari Version: 3.1.1 (5525.18) Build

  • Error - Journal Entry in R12 -"This balancing segment value....."

    Hello Friends, On R12 -> PROD version When I enter an Account in Journal, I am getting Error - > "This balancing segment value is not valid for current Ledger" It is completly a new setup of R12 accounts.

  • Why i cant view package body ?

    hi all, i cant view package body in my pl/sql. pls help. tks.

  • How to navigate from WD iView to another WD iView

    Hi experts, I'm wondering the best way to do a navigation from WD to another one, I've triyed absolute and relative navigation and neither of two works. I'll try to explain what am I doing: Application A wich is running in a iView needs to call an Ap

  • Canon HF10 and Apple TV

    I'm thinking about buying the Canon HF10 and in my research I've got a couple of questions that I just wanted to be sure about. Am I correct that the file one would download off of the flash card is an AVCHD H.264 formatted file? What is the exact fi