我是一名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&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"" distributionSites="Fort Worth TX, USA<br/>Jaguariuna, Brazil" formFactor="QWERTY Side Slider" franchise="Social Messaging" hwDesignCentre="Libertyville" keyFeatures="Rich Web Experience- Webkit, Flash with Huge 16:9 WVGA Screen<br/>The Premier 2.X Android Experience from Google<br/>Thinnest QWERTY Slider available at 13.7mm Thin<br/>Work & Personal Life Integrated: Unified Calendars, Email & 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并根据模式创建不同的数据文件。 在此先感谢。