integer type

Discussion in 'XML' started by veeman, Sep 21, 2006.

  1. veeman

    veeman Guest

    Can someone please write an example containing one element which value is
    integer type, and one attribute which value is also integer type:

    Is it something like this:

    <SomeAttribute AttrType:type="integer"

    How to specify value of 3 for example? When I parse it, will I get 3 as an
    integer or as a string?

    thank you very much!
    veeman, Sep 21, 2006
    #1
    1. Advertising

  2. veeman

    George Bina Guest

    Hi,

    It is not clear from your post what exactly you are looking for. For
    instance

    <OneElement oneAttribute="1">2</OneElement>

    is an example containing OneElement whose value is 2 (that is integer)
    and oneAttribute whose value is 1 (again integer).

    The common APIs for parsing XML documents DOM and SAX do not offer a
    method that returns Integer to get the value of an attribute or of an
    element. You can however try to convert the attribute value or the
    value of the text content of an element to Integer and see if that
    fails or not. Also if you use a schema then you can specify there that
    you want integer values and if the document is valid against that
    schema then you know that you will be able to convert those values to
    Integer.

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com


    veeman wrote:
    > Can someone please write an example containing one element which value is
    > integer type, and one attribute which value is also integer type:
    >
    > Is it something like this:
    >
    > <SomeAttribute AttrType:type="integer"
    >
    > How to specify value of 3 for example? When I parse it, will I get 3 as an
    > integer or as a string?
    >
    > thank you very much!
    George Bina, Sep 21, 2006
    #2
    1. Advertising

  3. veeman wrote:
    > When I parse it, will I get 3 as an integer or as a string?


    That depends on the tool you're using to parse it. Most parsers will
    return the string, but converting string to integer is trivial and some
    tools (eg XPath/XSLT) do so automagically if it's clear from context
    that this is your intent. A schema-aware parser, or a data-binding
    parser, may return the value directly as integer if they know from the
    schema or binding that this is what you expected back.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Sep 21, 2006
    #3
  4. veeman

    Andy Dingley Guest

    veeman wrote:

    > How to specify value of 3 for example? When I parse it, will I get 3 as an
    > integer or as a string?


    XML protocol itself only uses string types, not integers (URLs, NAMEs,
    IDREFs and maybe binary too, but not an integer)

    XML Schema specifies data typing, which means that the "string" in XML
    must represent an integer. A non-integer string would thus still be
    well-formed (good as far as XML goes) but would stop being valid (good
    for both XML and the relevant DTD or Schema)

    If you use a simple non-Schema aware parser, then you'll get the string
    "3"

    If you use a smarter parser that understands Schema and has an
    appropriate DOM interface to it, then it may also offer you a method
    that could retrieve 3 as a typed integer value. Probably it would also
    have some low-level string interface that returned it as "+3.00" or
    however the string had literally been supplied.

    For a dumb parser to recognise a string "3" as a potential integer and
    return it as the integer 3 _without_ having been told to do this by a
    data type in the Schema would be an error.

    If the intelligent parser can retrieve the document but not the Schema,
    then it has to treat the string as a string and not do anything about
    data typing. It's fundamental that XML (unlike SGML) keeps working even
    when you don't have the Schema to hand, but obviously it has to lose
    some of the extra, smarter features.

    So to get integers as integers, then you need three things: a Schema
    that defines the type, a parser and DOM smart enough to understand
    this, and an accessible connection between the two.
    Andy Dingley, Sep 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,947
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    No Math.min(Integer, Integer)?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 29, 2003, in forum: Java
    Replies:
    0
    Views:
    502
    =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Jul 29, 2003
  3. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    2
    Views:
    488
    Yu SONG
    Oct 15, 2004
  4. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    6
    Views:
    45,391
    JavaBean2010
    Apr 7, 2010
  5. FE
    Replies:
    6
    Views:
    514
    Balog Pal
    Aug 4, 2009
Loading...

Share This Page