gpt4 book ai didi

android - 来自 XML 字符串的 HashMap - Android

转载 作者:行者123 更新时间:2023-11-29 22:09:47 24 4
gpt4 key购买 nike

我将 xml 数据以字符串形式存储到用户首选项中。我想从这个 xml 字符串创建 hashmap。请帮我;这是我的 xml 字符串;

    String data = " <modules> <Calls> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Calls> <Cases> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Cases> <CFM_CoBuyer> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </CFM_CoBuyer> <Contacts> <access>89</access> <delete>-99</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Contacts> <Inv_Inventory> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Inv_Inventory> <Meetings> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Meetings> <Notes> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Notes> <Opportunities> <access>89</access> <delete>-99</delete> <edit>90</edit> <export>-99</export> <import>-99</import> <list>80</list> <view>90</view> </Opportunities> <Tasks> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Tasks> <Trd_TradeIns> <access>89</access> <delete>90</delete> <edit>90</edit> <export>90</export> <import>90</import> <list>90</list> <view>90</view> </Trd_TradeIns> </modules> ";

我想从数组中的“modules”标签中检索模块,并且该数组必须包含每个模块的子标签。请提出一些解决方案。

最佳答案

你可以使用节点列表

Document document = null;
NodeList nodeList = null;
Node node = null;

nodeList = document.getElementsByTagName("modules").item(0).getChildNodes();
HashMap <String,Object> localParameterMap = new HashMap<String,Object>();

for(int i=0; i<nodeList.getLength(); i++){
node = nodeList.item(i);
if(node.getNodeName().equals("Calls")){
Collection objCollection = readAttributeList(node);
localParameterMap.put(ATTRIBUTE_LIST, objCollection);
}
}

如何 update XML Dynamically

关于android - 来自 XML 字符串的 HashMap - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9920544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com