2
回答
xml,怎么通过dom用java读取出item的值
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
对于如下的xml,怎么通过dom用java读取出item的值啊?
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> 
    <!-- The time zone picker screen has two levels.  The first level allows the user to choose a region. -->
    <string-array name="timezone_filters"> 
    <!-- The next level of the time zoner picker should show time zones from the Americas. -->
        <item>America</item> 
    <!-- The next level of the time zoner picker should show time zones from Europe. -->
        <item>Europe</item> 
    <!-- The next level of the time zoner picker should show time zones from Africa. -->
        <item>Africa</item> 
    <!-- The next level of the time zoner picker should show time zones from Asia. -->
        <item>Asia</item> 
    <!-- The next level of the time zoner picker should show time zones from Australia. -->
        <item>Australia</item> 
    <!-- The next level of the time zoner picker should show time zones from Pacific. -->
        <item>Pacific</item> 
    <!-- The next level of the time zoner picker should show time zones from ALL regions. -->
        <item>All</item> 
    </string-array> 
</resources> 

我是这样写的:
NodeList nodeList = doc.getElementsByTagName("string-array");
NodeList itemList = nodeList.item(0).getChildNodes();
int itemSize = itemList.getLength();

for (int i = 0; i < itemSize ; i++)
{
    Node item = itemList.item(i);
    System.out.println("item value = " + item.getTextContent());
}
这样写打印出了好多空值、换行符。并且itemSize = 29 。
明显错了。但是该怎么写呢?
举报
顶部