gpt4 book ai didi

Android xml-样式表解析

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

如何在android中解析这个xml数据。

xml-stylesheet 格式与普通 xml 不同?

我需要这些字段;

科德买钞票卖钞票

<?xml version="1.0" encoding="ISO-8859-9"?>
<?xml-stylesheet type="text/xsl" href="isokur.xsl"?>
<Tarih_Date Tarih="20.07.2012" Date="07/20/2012">

<Currency Kod="USD" CurrencyCode="USD">
<Unit>1</Unit>
<Isim>AMERİKAN DOLARI</Isim>
<CurrencyName>US DOLLAR</CurrencyName>
<ForexBuying>1.7967</ForexBuying>
<ForexSelling>1.8054</ForexSelling>
<BanknoteBuying>1.7954</BanknoteBuying>
<BanknoteSelling>1.8081</BanknoteSelling>
<CrossRateUSD>1</CrossRateUSD>
<CrossRateOther></CrossRateOther>
</Currency>

<Currency Kod="EUR" CurrencyCode="EUR">
<Unit>1</Unit>
<Isim>EURO</Isim>
<CurrencyName>EURO</CurrencyName>
<ForexBuying>2.1998</ForexBuying>
<ForexSelling>2.2104</ForexSelling>
<BanknoteBuying>2.1983</BanknoteBuying>
<BanknoteSelling>2.2137</BanknoteSelling>
<CrossRateUSD></CrossRateUSD>
<CrossRateOther>1.2243</CrossRateOther>
</Currency>

最佳答案

Android 提供了大部分 java 的 api(SAX 和 DOM)来解析 XML 文档。您可以执行类似下面的操作来解析 xml 并获取所需的字段。

DocumentBuilder docBuild= docBuildFactory.newDocumentBuilder();
InputSource in= new InputSource();
in.setCharacterStream(new StringReader(xml));
Document doc = docBuild.parse(in);
NodeList nodes = doc.getElementsByTagName("Currency");
Element e = (Element)nodes.item(i);
XMLfunctions.getValue(e, "BanknoteBuying")

这一定能解决您的问题.... :)

关于Android xml-样式表解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11665306/

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