Reputation: 2137
Here is the XML
file:
<SketchPad>
<Player>
<TotalPage>2</TotalPage>
<BackgroundImage>/Users/ltlab/Library/Application Support/iPhone Simulator/5.1/Applications/D84490FE-3450-456C-A8FE-16BE8B1EB12C/Documents/publicUser_1356864779.441782_local.png</BackgroundImage>
<Name>1</Name>
<SelfBackgroundImage>sound.png</SelfBackgroundImage>
<Type>Record</Type>
<X_Value>0.000000</X_Value>
<Y_Value>38.000000</Y_Value>
<Height_Value>50.000000</Height_Value>
<Width_Value>50.000000</Width_Value>
<File_Path>null</File_Path>
</Player>
<Player>
<TotalPage>2</TotalPage>
<BackgroundImage>/Users/ltlab/Library/Application Support/iPhone Simulator/5.1/Applications/D84490FE-3450-456C-A8FE-16BE8B1EB12C/Documents/publicUser_1356864779.441782_local.png</BackgroundImage>
<Name>1</Name>
<SelfBackgroundImage>8_128x128.png</SelfBackgroundImage>
<Type>Stamp</Type>
<X_Value>7.000000</X_Value>
<Y_Value>716.000000</Y_Value>
<Height_Value>80.000000</Height_Value>
<Width_Value>80.000000</Width_Value>
<File_Path>null</File_Path>
</Player>
<Player>
<TotalPage>2</TotalPage>
<BackgroundImage>/Users/ltlab/Library/Application Support/iPhone Simulator/5.1/Applications/D84490FE-3450-456C-A8FE-16BE8B1EB12C/Documents/publicUser_1356864779.441782_local.png</BackgroundImage>
<Name>1</Name>
<SelfBackgroundImage>duck.png</SelfBackgroundImage>
<Type>Stamp</Type>
<X_Value>570.000000</X_Value>
<Y_Value>715.000000</Y_Value>
<Height_Value>80.000000</Height_Value>
<Width_Value>80.000000</Width_Value>
<File_Path>null</File_Path>
</Player>
</SketchPad>
What I want to do is to collect all the data inside the tag .
$(xml).find("X_Value").toArray();
But it returns an array still containing the tag like this:
[<x_value>0.0000000<x_value>,<x_value>7.0000000<x_value>,<x_value>570.0000000<x_value>]
Not an expected array:
[0.0000000,7.0000000,570.0000000]
How can I do to directly extract the values inside the tag, making an array?
I don't really know how to manipulate the jQuery.map()
.
Upvotes: 0
Views: 123
Reputation: 490243
Use this instead...
$(xml).find("X_Value").map(function() { return $(this).text(); }).get();
Your previous example is getting a reference to those elements. This replaces the references with the inner text.
Upvotes: 3