Getting an attribute value

64 views
Skip to first unread message

Gabriella Turek

unread,
Dec 5, 2012, 11:09:45 PM12/5/12
to joox...@googlegroups.com
As part of my testing, I want to verify that I edited the attribute value correctly.

With the following 2 lines of code I identify correctly the tags my the attribute appears in
        FastFilter ff1 = JOOX.tag("Climate");
        Match x1 = JOOX.$(updated).find(ff1);

The tags in question being:
[<Climate Altitude_m="0" AnnualPET="Use default" AnnualPET_mm="0" Latitude_deg="0" MeanAnnualRainfall_mm="1800" MeanAnnualTemp_C="0" RainfallSeasonalVariation="Use default" SeasonalPETVariation="Use default">
                                <ListOfSnowFall/>
                            </Climate>,
<Climate MeanAnnualRainfall_mm="1800">
                                <ListOfSnowFall/>
                            </Climate>]

But how do I get the value of the attribute? I've tried different approaches including a simple JQuery like
String str = JOOX.$("Climate").attr("MeanAnnualRainFall_mm");
But I keep getting an empty string back instead of "1800"


Lukas Eder

unread,
Dec 6, 2012, 3:13:20 AM12/6/12
to joox...@googlegroups.com, tet...@gmail.com
Hello Gabriella,

There are some subtle differences between jQuery and jOOX. Remember
that jQuery is executed in the context of an HTML DOM, which is
globally available. Hence, in jQuery, $("Climate") is actually a
short-cut for writing $(document).find("Climate").

jOOX cannot statically access any "global" DOM document, hence
$("Climate") has a different semantics, it creates a new document with
a <Climate/> root element in it.

What you want to do is write something along the lines of:

String str = $(updated).find("Climate").attr("MeanAnualRainFall_mm");

Cheers
Lukas
Message has been deleted

Lukas Eder

unread,
Dec 12, 2012, 2:26:37 AM12/12/12
to joox...@googlegroups.com, Gabriella Turek
I actually had a typo in my attribute name:

// I wrote:
String str = $(updated).find("Climate").attr("MeanAnualRainFall_mm");

// Instead of
String str = $(updated).find("Climate").attr("MeanAnnualRainFall_mm");

Anyways, can you provide me with a reproducible test case? i.e. a
sample XML file, parsed and passed to jOOX, to illustrate how this
isn't working for you?

Cheers
Lukas

2012/12/11 Gabriella Turek <tet...@gmail.com>:
> Hi Lucas, that is one of the things that I tried as well, but I keep getting
> a null string back.
> Gaby
>
Reply all
Reply to author
Forward
0 new messages