Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > integer type

Reply
Thread Tools

integer type

 
 
veeman
Guest
Posts: n/a
 
      09-21-2006
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!


 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      09-21-2006
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!


 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      09-21-2006
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
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      09-21-2006

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Target type ieee.std_logic_1164.std_ulogic in signal assignment isdifferent frim expression type std.standard.integer. Diego UTN-FRP VHDL 4 11-29-2009 01:29 AM
enum promote to bool type rather than Integer type? FE C++ 6 08-04-2009 03:21 PM
is there a way to AutoParse a string to another type - e.g. if aDate format then date, else if integer than Integer etc ????? Greg Hauptmann Ruby 6 08-06-2008 04:52 PM
CType(x,Integer) vs. Integer.Parse(x) =?Utf-8?B?Sm9l?= ASP .Net 7 02-07-2006 02:30 AM
No Math.min(Integer, Integer)? =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 0 07-29-2003 07:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57