You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "John A. Mitchell" <ja...@scico.sandia.gov> on 2004/02/06 03:08:55 UTC
accessing numerical attribute values
I am a so-called newbie at this -- here goes.
I am trying to exract the value "double startTime" from the xml below.
I have an "Element" but don't know
how to "decode" or "transcode" the attribute value into a "double"
<timeBlock>
<startTime value="0.336"/>
<timeIncrement value=".0003"/>
</timeBlock>
double getStarTimet(Element e){
String startTime = new String("startTime");
String value = e.getAttribute(startTime);
double value = ????
return value;
}
Also, when I print "value"; say like "System.out.println(value)" I get
an empty string?
Can someone point me in the right direction here?
Here is the c++ that I have effectively used in the past (but now I need
the Java):
double Jpp_ParsedValues::getDoubleAttribute(DOMElement* e, const char*
name){
// This function retrieves the value of the attribute "name" on the
element
const XMLCh* start = XMLString::transcode(name);
const XMLCh* c = e->getAttribute( start );
delete start;
char* s = XMLString::transcode(c);
double value = atof(s);
delete s;
return value;
}
Now I need to do this in "Java" using xerces-j
I don't know where to look to figure this out.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: accessing numerical attribute values
Posted by Andy Clark <an...@apache.org>.
John A. Mitchell wrote:
> double value = atof(s);
> [...]
>
> Now I need to do this in "Java" using xerces-j
>
> I don't know where to look to figure this out.
This really isn't the right forum for this question because
it's really about Java programming. But, to answer your
question, try:
double value = Double.parseDouble(s);
It will throw a NumberFormatException if it's bad and you
need to catch that exception.
--
Andy Clark * andyc@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org