![]() |
|
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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! |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
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. |
|