Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to read an element from a xml file

    Hi,

    I'm writing a multi-language app.

    In order to reduce transaction, in a xml file, necessary texts will be kept
    and retrived when needed. For this, I want to use DataSource and ResultSet classes. (Am I Right?)

    Here is the xml file.
    Code:
    <texts>
        <language1>
            <text><code>100</code><word>morning</word></text>
            <text><code>200</code><word>afternoon</word></text>
        </language1>
        <language2>
            <text><code>100</code><word>午前</word></text>
            <text><code>200</code><word>午後</word></text>
        </language2>
    </texts>
    Two languages, language1 and language2, have two texts whose codes are
    100 and 200 respectively. I want the XML path to be /texts/language1 and
    /texts/language2 for language1 and language2 respectively.

    Here are the codes I expect to be. (Sorry I couldn't find any sample codes.)

    Code:
    DataSource dataSource = new DataSource();
    dataSource.setDataFormat( DSDataFormat.XML );
    dataSource.setDataURL( "xml/language.xml" );
    
    dataSource.setRecordXPath( "/texts/language1/" );
    
    ResultSet resultSet = new ResultSet( dataSource );
    Record record = resultSet.find( "code", "200" );
    1. Am I on the right way ?
    2. resultSet.getLength() always returns 1000. What am I missing ?
    3. If a record is found that way successfully, is it possible to read field
    values of the record by calling record.getAttribute() method ?

    Well.... I encourage myself by talking to myself thers is no foolish question.
    Any tiny hint will be appreciated.

    Regards
    Last edited by veritas; 6 Jul 2010, 02:46.
Working...
X