这是XML
文件:
<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>
我要做的是收集标记内的所有数据。
$(xml).find("X_Value").toArray();
但它返回的数组仍包含如下标记:
[<x_value>0.0000000<x_value>,<x_value>7.0000000<x_value>,<x_value>570.0000000<x_value>]
不是预期的数组:
[0.0000000,7.0000000,570.0000000]
如何直接提取标签内的值并组成一个数组?
我真的不知道如何操作
jQuery.map()
。 最佳答案
改用这个...
$(xml).find("X_Value").map(function() { return $(this).text(); }).get();
您先前的示例正在引用这些元素。这将引用替换为内部文本。