Android xml样式表解析

问题描述:

如何解析android中的这个xml数据。Android xml样式表解析

xml-stylesheet格式与正常xml不同吗?

我需要这些字段;

KOD BanknoteBuying BanknoteSelling

<?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") 

这必须解决您的问题.... :)

我不认为它应该是不同的。最后,这也是一个由标签和属性组成的XML文件。
如果您需要刷新有关解析XML this post可能会让你感到高兴。

您可以放心地忽略xml-stylesheet processing instruction,并像处理任何其他XML一样解析XML。 xml-stylesheet是一种暗示演示代理(如浏览器)的转换,它将呈现XML,因为它将被呈现。代理决定是否使用样式表。

在这种情况下的代理是您的应用程序。

如果你真的想要的isokur.xsl XSLT样式表被应用到你的XML,那么我想你可能是出于运气。据我所知,目前还没有Android上的XSLT处理器。我们正在考虑将撒克逊移植到这个平台上的可能性,但它今天不存在。