您的位置:首页 > 移动开发 > Objective-C

XML and Windows CE 3.0

2003-05-22 08:39 531 查看
 

XMLandWindowsCE3.0<?xml:namespaceprefix=ons="urn:schemas-microsoft-com:office:office"/>

MichaelReeves
MicrosoftCorporation

November2000

Summary:WindowsCE3.0operatingsystemextendstherangeofoptionsavailabletodevelopersbyprovidingasubsetofExtensibleMarkupLanguage(XML)functionality.ThisdocumentdescribesthefeaturesofXMLthathavebeenincorporatedintoWindowsCEandthedifferencesbetweenusingXMLonaWindowsCE–basedplatformandonaWindows-baseddesktopcomputer.(9printedpages)

Content

Introduction
ExtensibleMarkupLanguage
   
WebServicesandXML
XMLforWindowsCE
   
ValidatingData
   
DocumentManagement
   
FormattingComplexDataforPresentation
   
XMLHTTP
   
InstantiationofCOMObjectsThroughXSL

Introduction

TheMicrosoft®Windows®CE3.0operatingsystemextendstherangeofoptionsavailabletodevelopersbyprovidingasubsetofExtensibleMarkupLanguage(XML)functionality.ThisdocumentdescribesthefeaturesofXMLthathavebeenincorporatedintoWindowsCEandthedifferencesbetweenusingXMLonaWindowsCE–basedplatformandonaWindows-baseddesktopcomputer.ForgeneralinformationaboutXML,seethedocumentationavailableintheMSDNOnlineLibrary.(Notethatthroughoutthisarticle,MSXMLreferstotheXMLparseravailablefromMicrosoft,andXMLreferstothemarkuplanguage.)

ExtensibleMarkupLanguage

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,seeTheProgrammableWeb:WebServicesProvidesBuildingBlocksfortheMicrosoft.NETFramework.

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

TheXMLHTTPobjectanditspropertiesareoutlinedintheIXMLHttpRequestInterfacedocumentationintheMSDNOnlineLibrary.

InstantiationofCOMObjectsThroughXSL

WindowsCEsupportsinstantiationofCOMobjects,suchasActiveXcontrols,throughtheXSLscriptinterface.ThefollowingscriptdemonstratesinstantiationofafictitiousCOMobject,“MyCorp”:
<xsl:script>functionTestCOMObject()
{
    varObj1=newActiveXObject("MyCorp.MyComponent");
    vary=Obj1.Process();//CreateanewCOMobjectanduseittohandle
 //additionalprocessing.
   returny;
}
</xsl:script>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息