资源描述:
《使用stax解析xmlpart2(使用stax解析xml二)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、使用stax解析xmlpart2(使用StAX解析XML二)UsingStAXtoparseXML,thesecondpart:pullparsingandeventsResearchonStAXbasedoneventiteratorAPIDocumentoptionsPrintthispageSendthispageasanemaildiscussLevel:IntermediatePeterNehrer(pnehrer@eclipticaLca),freelancewriter,independentconsuItant05July2007St
2、reamingAPIforXML(StAX)basedoneventiteratorAPIhastheuniqueadvantagesofotherXMLprocessingmethodsbothinperformanceandusability・ThefirstpartintroducesStAXanddiscussesitspointerbasedAPIindetai1.ThisarticlefurtherdiscussesthebenefitsofeventbasediteratorAPIanditsbenefitsforJavadevelop
3、ers・ParsingXMLwithStAXThefirstpart(seeresources)mentionsthatStAXprovidestwostylesofprocessingXML'sAPI.PointerbasedAPIisalowlevelmethodforparsingXML・Usingthismethod,theapplicationmovesthepointeralongtheXMLtagstream,andcheckstheparser,sstateateachsteptounderstandmoreinformationab
4、outtheparsedcontent・Thismethodisveryefficient,especiallyforresourceconstrainedenvironments・However,pointerbasedAPIisnotobject-oriented,andthereforenotsuitableforJavaapplications,especiallyintheenterprisedomainwhichisjustasimportantasscalabilityandmaintainabilityofcode・Forexampl
5、e,multiWebserviceusinggeneralcomponentsprocessingthemessageenvelope,andthespecificcontentofthemessageprocessing(suchasparameterbindings)entrustedtoothercomponents,thiscasecanbenefitfromtheobject-orientedmethodin.AnotherstyleofAPIprovidedbyStAXfocusesoneventobjects・Aswithpointer
6、basedAPI,whichisaXMLanalyticalmethodbasedonpull:applicationsusingthemethodsprovidedoutofeacheventfromtheparser,inaccordancewiththeneedsofhandlingtheevent,andsoon,untilthecompletionoff1owanalysis(orapplicationdecisiontostopparsing)・BriefintroductionofXMLEventReaderinterfaceThema
7、ininterfaceoftheeventiteratorAPIisXMLEventReader・ComparedwithXMLStreamReader,ithasfewermethods・ThisisbecauseXMLEventReaderisusedtoiteratetheeventobjectstream(infact,XMLEventReaderextendsjava.util.Iterator)・Allinformationaboutparsingeventsisencapsulatedintheeventobjectratherthan
8、thereader・TouseAPIbasedoneventiterator,theapplicationm