XML and Windows CE 3.0
2003-05-22 08:39
531 查看
XMLandWindowsCE3.0<?xml:namespaceprefix=ons="urn:schemas-microsoft-com:office:office"/>
MichaelReevesMicrosoftCorporation
November2000
Summary:WindowsCE3.0operatingsystemextendstherangeofoptionsavailabletodevelopersbyprovidingasubsetofExtensibleMarkupLanguage(XML)functionality.ThisdocumentdescribesthefeaturesofXMLthathavebeenincorporatedintoWindowsCEandthedifferencesbetweenusingXMLonaWindowsCE–basedplatformandonaWindows-baseddesktopcomputer.(9printedpages)
Content
Introduction
TheMicrosoft®Windows®CE3.0operatingsystemextendstherangeofoptionsavailabletodevelopersbyprovidingasubsetofExtensibleMarkupLanguage(XML)functionality.ThisdocumentdescribesthefeaturesofXMLthathavebeenincorporatedintoWindowsCEandthedifferencesbetweenusingXMLonaWindowsCE–basedplatformandonaWindows-baseddesktopcomputer.ForgeneralinformationaboutXML,seethedocumentationavailableintheExtensibleMarkupLanguage
XMLisameta-markuplanguagethatprovidesaformatfordescribingstructureddataandallowsdeveloperstoeasilydescribeanddeliverrich,structureddatafromanyapplicationinastandard,consistentway.XMLfacilitatesmoreprecisedeclarationsofcontentandprovidesmoremeaningfulsearchresultsacrossmultipleplatforms.Inaddition,XMLisenablinganewgenerationofWeb-basedapplicationsforviewingandmanipulatingdata.ThepowerandbeautyofXMLcomesfromitsmaintainingtheseparationoftheuserinterfacefromthestructureddata.WhileHypertextMarkupLanguage(HTML)tagscandisplayawordinboldfaceoritalics,XMLprovidesaframeworkfortaggingstructureddata.AnXMLtagcanindicatethatthedataassociatedwiththetagisaretailprice,asalestax,abooktitle,anamountofprecipitation,oranyotherdesireddata.AsXMLtagsareadoptedbyorganizationsfortheirintranets,andbyothersacrosstheInternet,theabilitytosearchforandmanipulatedata,regardlessoftheapplicationswithinwhichthedataresides,willincrease.OnceanapplicationlocatesXMLdata,theapplicationcandeliverthedataoverthenetworkandpresentthedatainaWebbrowser(suchasMicrosoft®InternetExplorer)inanynumberofways,ortheap
4000
plicationcanhandoffthedatatootherapplicationsforfurtherprocessingandviewing.
XML,whichprovidesadatastandardthatcanencodethecontent,semantics,andschemataforawidevarietyofcasesrangingfromsimpletocomplex,canbeusedtomarkupthefollowing:
Anordinarydocument
Astructuredrecord,suchasanappointmentrecordorpurchaseorder
Anobjectwithdataandmethods,suchasthepersistentformofaJavaobjectorActiveX®control
Adatarecord,suchastheresultsetofaquery
MetacontentaboutaWebsite,suchasChannelDefinitionFormat(CDF)
Agraphicalpresentation,suchasanapplication'suserinterface
Standardschemaentitiesandtypes
AlllinksbetweeninformationandpeopleontheWeb
Oncethedataisontheclientdesktop,itcanbemanipulated,edited,andpresentedinmultipleviewswithoutreturntripstotheserver.Serverscannowbecomemorescalable,duetolowercomputationalandbandwidthloads.Also,becausedataisexchangedintheXMLformat,itcanbeeasilymergedfromdifferentsources.
WebServicesandXML
Unlikecurrentcomponenttechnologies,Webservicesdonotuseobject-model-specificprotocolssuchasDistributedComponentObjectModel(DCOM),RemoteMethodInvocation(RMI),orInternetInter-ORBProtocol(IIOP)thatrequirespecific,homogeneousinfrastructuresonboththeclientandservicemachines.Whileimplementationstightlycoupledtospecificcomponenttechnologiesareperfectlyacceptableinacontrolledenvironment,theybecomeimpracticalontheWeb.Asthesetofparticipantsinanintegratedbusinessprocesschanges,andastechnologychangesovertime,itbecomesverydifficulttoguaranteeasingle,unifiedinfrastructureamongallparticipants.Webservicestakeadifferentapproach:TheycommunicateusingubiquitousWebprotocolsanddataformatssuchasHypertextTransferProtocol(HTTP)andXML.AnysystemsupportingtheseWebstandardswillbeabletosupportWebservices.Furthermore,aWebservicecontractdescribestheservicesprovidedintermsofthemessagestheWebserviceacceptsandgeneratesratherthanhowtheserviceisimplemented.Byfocusingsolelyonmessages,theWebservicesmodeliscompletelyindependentofthelanguage,platform,andobjectmodelused.AWebservicecanbeimplementedusingthefullfeaturesetofanyprogramminglanguage,objectmodel,andplatform.
XMListheobviouschoicefordefiningastandardyetextensiblelanguagetorepresentcommandsandtypeddata.Whilerulesforrepresentingcommandsandtypeddatausingothertechniques(suchasencodingasaquerystring)couldbedefined,XMLisspecificallydesignedasastandardmetalanguagefordescribingdata.
XMLisalsotheenablingtechnologyforWebservicecontracts.TheServiceContractLanguage(SCL)isanXMLgrammarfordocumentingWebservicecontracts.BecauseSCLisXML-based,contractsareeasyforbothdevelopersanddevelopertoolstocreateandinterpret.
FormoreinformationaboutMicrosoftWebServices,see
XMLforWindowsCE
MicrosoftWindowsCE3.0supportsasubsetofMSXML2.0functionality.Specifically,WindowsCEdoesnotsupportthefollowingfeatures:Simpledatatypesonattributes
Additionofan"id"datatypeforelements
Assignmentofdatatypesthroughelementnames
Dataislands
Databinding
MimeTypeviewer
BackwardcompatibilitywiththeMicrosoftXMLDocumentObjectModel(DOM)supportedbyMicrosoftInternetExplorer4.0
Also,WindowsCEprovidesonlylimitedXMLsecurity.
SomeoftheMSXML2.0featuresthataresupportedinWindowsCEare:
XMLvalidationthroughschema,namespace,anddatatypesupport.
TheabilitytobuildandmanagecomplexdocumentsanddatathroughDocumentObjectModel(DOM)support.
WebbrowserformattingthroughExtensibleStylesheetLanguage(XSL)support.
AutomateddocumentrequestsandparsingfunctionsthroughtheuseofXMLHTTPfeatures.
WindowsCEalsosupportstheabilitytoinstantiateComponentObjectModel(COM)objectswithinblocksofanXSLscript,whichisafeatureofMSXML2.5.
ValidatingData
MSXMLforWindowsCEsupportsatechnicalpreviewreleaseofXMLschemata.TheXMLschemasupportisasubsetoftheWorldwideWebConsortium(W3C)XMLdatasubmissionandisfunctionallyveryclosetotheW3CDocumentContentDescription(DCD)submission.ConsiderthefollowingXMLfile:
<CONTACTS>
<CONTACT>
<NAME>StephanieSmith</NAME>
<BIRTHDATE>1971-07-01</BIRTHDATE>
<EMAIL>ssmith@abcdef.com</EMAIL>
<PHONE>(425)111-1111</PHONE>
</CONTACT>
<CONTACT>
<NAME>BillWilliams</NAME>
<BIRTHDATE>1968-09-17</BIRTHDATE>
<EMAIL>billw@abcdef.com</EMAIL>
<PHONE>(425)111-1111</PHONE>
</CONTACT>
<CONTACT>
<NAME>ChristopherJones</NAME>
<BIRTHDATE>1999-09-08</BIRTHDATE>
<EMAIL>cjones@abcdef.com</EMAIL>
<PHONE>(425)111-1111</PHONE>
</CONTACT>
</CONTACTS>
WiththenewXMLschemasupportinMSXMLforWindowsCE,theabovedatacanbevalidatedagainstaschemabydeclaringthefollowingnamespaceontherootelement:
<CONTACTSxmlns="x-schema:contactSchema.xml">
ThissetstheschemacontactSchema.xmlasthedefaultnamespaceforthedocument.Othernamespacescanbedeclaredthroughoutthedocumentifdesired,but,wherenonamespaceisspecified,thedefaultwillapply.
ThecompleteschemafortheaboveXMLdocumentisasfollows:
<Schemaxmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementTypename="NAME"content="textOnly"/>
<ElementTypename="BIRTHDATE"
content="textOnly"
dt:type="date"/>
<ElementTypename="EMAIL"content="textOnly"/>
<ElementTypename="PHONE"content="textOnly"/>
<ElementTypename="CONTACT"content="eltOnly">
<elementtype="NAME"/>
<elementtype="BIRTHDATE"/>
<elementtype="EMAIL"/>
<elementtype="PHONE"/>
</ElementType>
<ElementTypename="CONTACTS"
content="eltOnly"
order="many">
<elementtype="CONTACT"/>
</ElementType>
</Schema>
Theattribute:
xmlns='urn:schemas-microsoft-com:xml-data'
setsthedefaultnamespacefortheXMLdocumentastheschemanamespace.ThismeansthattheschemamustconformtothesyntaxforXMLschemata.Similarly,theattribute:
xmlns:dt='urn:schemas-microsoft-com:datatypes'
declaresthedatatypenamespace.Thismeansthatdatatypescannowbedeclaredthroughouttheschema.(NotethatthedtprefixonthetypeattributeisusedtotypetheBIRTHDATEvalue.)
DocumentManagement
TheDOMisaplatform-neutralandlanguage-neutralinterfacethatpermitsscriptstoaccessandupdatethecontent,structure,andstyleofadocument.TheDOMincludesamodelforhowastandardsetofobjectsrepresentingHTMLandXMLdocumentsarecombinedandaninterfaceforaccessingandmanipulatingthem.TheMicrosoftXMLParseronWindowsCEhasfullDOMsupportincompliancewiththeW3CDOMrecommendation.Inaddition,italsohastheMicrosoftextensionsthatallowaccesstotypeddataandnamespaceinformation,creationofnodesbynodetype,andsoon.ThefollowingisascriptthatloadsanXMLdocumentcontainingthecontactinformationandusesXSLpatternmatchingtodisplaythephonenumberofthecontactwiththenameof"BillWilliams":functionshowPhone()
{
varroot=Contacts.documentElement;
varselectedElems= root.selectNodes("CONTACT[NAME='BillWilliams']");
varbillElem=selectedElems.item(0);
varphone=billElem.childNodes.item(3).nodeTypedValue;
alert("BillWilliamsphonenumberis"+phone);
}
TheselectNodesmethodusesXSLpattern-matchingtoretrieveanodelist.Inthiscase,thescriptlooksforallCONTACTelementsthathaveaNAMEelementwiththevalueof"BillWilliams."Becausethereisonlyoneelementthatmatchesthispattern,selectNodesreturnsanodelistoflengthone.
FormattingCom
ae27
plexDataforPresentation
MSXMLonWindowsCEalsoprovidessupportforXSL,whichallowsformorecomplexdisplayofXMLdata.Forinstance,thepreviouscontactinformationcanbedisplayedinasimpletableformat.ThefirsttaskwouldbetocreateanXSLstylesheet:<xsl:stylesheetxmlns:xsl="uri:xsl">
<xsl:templatematch="/">
<H3>Contacts</H3>
<TABLEBORDER="1"CELLPADDING="1"CELLSPACING="0">
<TR>
<TDBGCOLOR="#C0C0C0"><B>Name</B></TD>
<TDBGCOLOR="#C0C0C0"><B>Phone</B></TD>
<TDBGCOLOR="#C0C0C0"><B>Email</B></TD>
</TR>
<xsl:for-eachselect="CONTACTS/CONTACT"order-by="EMAIL">
<TR>
<TD><I><xsl:value-ofselect="NAME"/></I></TD>
<TD><xsl:value-ofselect="PHONE"/></TD>
<TD><xsl:value-ofselect="EMAIL"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
ThisparticularstylesheetcreatesatableandusesthevaluesofselectedXMLelementstofillthetablewithinformation.Thestylesheetalsosortstheinformationbye-mailname(usingtheorder-byattributeonthexsl:for-eachelement).NotethattheorderinwhichthecontactinformationisdisplayeddiffersfromtheoriginalXMLdocument.
ThisstylesheetcanbeappliedtotheXMLdocumentthroughtheXMLObjectModel,whichisasetofapplicationprogramminginterfaces(APIs)thatallowinteractionwiththeelementsoftheXMLstructuredtree.ThetransformNodemethodonIXMLDOMNodepassesinanXSLtreeandusesthattreetotransformanXMLnodeintoanoutputstring.Inthefollowingcase,thatstringwillbeanHTMLstringthatgetsinsertedintothecurrentdocument:
functionshowContacts()
{
document.write(Contacts.transformNode(ContactsSS.documentElement);
}
Theabovescriptdisplaysthefollowinginthebrowser:
<?xml:namespaceprefix=vns="urn:schemas-microsoft-com:vml"/>
XMLHTTP
UsingtheXMLHTTPobject,theXMLtreeitselfcanbepostedasanobject.Inthefollowingscript,anXMLHTTPobjectiscreatedandpostsanXMLtreenamed"template"totheserverlocation:varhttpOb=newActiveXObject("Microsoft.XMLHTTP");
httpOb.Open("POST","http://myServer/postContact.asp",false);
varcontact=template.XMLDocument.documentElement;
contact.childNodes.item(0).text=contactName.value;
contact.childNodes.item(1).text=contactPhone.value;
contact.childNodes.item(2).text=contactEmail.value;
httpOb.send(template.XMLDocument);
TheXMLHTTPobjectanditspropertiesareoutlinedintheIXMLHttpRequestInterfacedocumentationinthe
InstantiationofCOMObjectsThroughXSL
WindowsCEsupportsinstantiationofCOMobjects,suchasActiveXcontrols,throughtheXSLscriptinterface.ThefollowingscriptdemonstratesinstantiationofafictitiousCOMobject,“MyCorp”:<xsl:script>functionTestCOMObject()
{
varObj1=newActiveXObject("MyCorp.MyComponent");
vary=Obj1.Process();//CreateanewCOMobjectanduseittohandle
//additionalprocessing.
returny;
}
</xsl:script>
相关文章推荐
- Windows Powershell创建对象
- 千年零一虫
- 独具量身定做特色的管理软件--数据大师
- delphi中的时间操作技术(2)
- 使用 .NET 框架将现有代码作为 Web 服务提供
- 移植到 Windows 2000 和 COM+
- 用VB和MTS开发多层数据库应用系统
- 用ASP备份数据库
- 关于win2000安装的2个问题
- DOM心得
- 利用hook截获进程的API调用
- Red Hat Linux 7.2汉化
- Inside Java2 SDK Source Internal 深入Java2 SDK原始码(一) Java2 SDK原始码概观
- Java 2 Micro Edition简介(四)
- 利用Java 编写手机应用程序 Motorola iDEN篇
- 利用pre-compiled headers技术以加速编译速度--以Borland C++ Builder为例(五)
- 统一部署 PowerShell 5.1
- 为Windows与Office 安装批量激活服务