0

我是一名 Android 开发人员,我必须创建一个通用组件来使用 sax 解析器解析 xml。对于任何类型的模式,我都应该创建一个通用组件,通过它我们可以解析 xml 并将其保存到数据文件(bean 或模型对象)中。

这对 SAX 是否可行,如果可以,您能帮我吗?

例如,

<ns:multiStockDataDownloadResponse xmlns:ns="http://service.tcs.web">
<ns:return>
<StockList>
<Stock changeData="-0.10" companyData="Sprint Nextel Corporation" lastData="5.21" marketCapData="15586.73" percChangeData="-1.88" tkr="S" > 
<customerProfile value="false" name="isNWCustomer" />
<customerProfile value="English" name="custLangPref" />
<customerProfile value="karthi.muthusamy@bankofamerica.com"
    name="fullEmailAddress" />
</Stock>
 <Stock changeData="+0.43" companyData="Vodafone Group Plc (ADR)" lastData="26.43" marketCapData="135649.83" percChangeData="2.05" tkr="VOD" > 
   <customerProfile value="false" name="isNWCustomer" />
<customerProfile value="English" name="custLangPref" />

</Stock>
 <Stock changeData="+0.12" companyData="Verizon Communications Inc." lastData="35.24" marketCapData="98672.00" percChangeData="0.34" tkr="VZ" >
  <customerProfile value="false" name="isNWCustomer" />

</Stock> 
<Stock changeData="+0.08" companyData="AT&amp;T Inc." lastData="30.43" marketCapData="180206.46" percChangeData="0.26" tkr="T" /> 
<Stock changeData="-0.22" companyData="Telefonica S.A. (ADR)" lastData="23.47" marketCapData="107117.00" percChangeData="-0.93" tkr="TEF" />  
</StockList>
</ns:return>
</ns:multiStockDataDownloadResponse>

另一个样本是

<?xml version="1.0" encoding="UTF-8"?>
<ns:getProductDescriptionResponse xmlns:ns="http://services.tcs.web"><ns:return><Service>
<ServiceDescription serviceClass="TEST" serviceId="getProductDescription1" serviceName="Get Customer Product Info" serviceVersion="1.0" />
<ProductDescription disclosureStatus="Green" displaySize="3.7&quot;" distributionSites="Fort Worth TX, USA&lt;br/>Jaguariuna, Brazil" formFactor="QWERTY Side Slider" franchise="Social Messaging" hwDesignCentre="Libertyville" keyFeatures="Rich Web Experience- Webkit, Flash with Huge 16:9 WVGA Screen&lt;br/>The Premier  2.X Android Experience from Google&lt;br/>Thinnest QWERTY Slider available at 13.7mm Thin&lt;br/>Work &amp; Personal Life Integrated: Unified Calendars, Email &amp; Contacts" launchPriceTier="$301-$400" manufacturingSites="Tianjin, China (Lead Site)" marketName="DROID" modelNumber="A855" popi="Shareable" productId="1875" productName="Sholes CDMA" productSADate="10/22/2009" productSegment="Performance Smartphones" productStatus="End of Life" swDesignCentre="Libertyville" swPlatform="Android Eclair 1.0" technologies="CDMA 800/1900, CDMA EV-DO Release A, Bluetooth Class 2 Version 2.0+EDR, WiFi 802.11b/802.11g, aGPS (assisted)" />
<ShipAcceptanceDates>
    <Launch country="United States" customer="Verizon" launchType="Initial Launch" region="North America" saDate="10/22/2009" saStatus="FULL SA" />
    <Launch country="United States" customer="Verizon" launchType="UPGRADE 1" region="North America" saDate="05/31/2011" saStatus="On Plan" />
</ShipAcceptanceDates>
<ProductTeam>
    <Role coreId="Q14993" name="Mayur Talati" role="Supply Chain Program Manager" />
    <Role coreId="GWNQ46" name="Chippindale Cindy" role="Program Manager" />
    <Role coreId="KHALLMAN" name="KENNETH HALLMAN" role="Product Family Lead" />
    <Role coreId="WLMR06" name="Mike Reich" role="Device Project/Program Lead" />
</ProductTeam>
</Service></ns:return></ns:getProductDescriptionResponse>

在这两种情况下,该组件都必须解析 xml 并根据模式创建不同的数据文件。提前致谢。

4

0 回答 0