enginar
enginar

Reputation: 307

Android xml-stylesheet parsing

How can parsing this xml data in android.

xml-stylesheet format diffent from nomal xml?

I needs these fields;

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>

Upvotes: 1

Views: 422

Answers (4)

Michael Kay
Michael Kay

Reputation: 163272

If you actually want the isokur.xsl XSLT stylesheet to be applied to your XML, then I think you may be out of luck. As far as I'm aware, there isn't currently an XSLT processor available on Android. We're looking at the possibility of porting Saxon to this platform, but it's not there today.

Upvotes: 0

Peter Lillevold
Peter Lillevold

Reputation: 33910

You can safely ignore the xml-stylesheet processing instruction and parse the XML as you would any other XML. xml-stylesheet is a means of hinting to a presentation agent (such as a browser) a transformation that will present the XML as it is intended to be presented. It is still up to the agent to decide if it will use the stylesheet or not.

The agent in this case is your application.

Upvotes: 0

Errol Dsilva
Errol Dsilva

Reputation: 177

Android provides most of java's api's (SAX & DOM) to parse XML documents. You can do something like below to parse the xml and get the fields you need.

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

This must solve your problem.... :)

Upvotes: 1

Andy Res
Andy Res

Reputation: 16043

I don't believe it should be different. In the end this also is an XML file consisting from tags and attributes.
If you need a refresh about parsing XML this post may warm you up.

Upvotes: 1

Related Questions