320 likes | 495 Views
XML case study: SyncML. Sean C. Sullivan <sean> at <seansullivan> <.com>. Agenda. XML and SyncML Sync4j project Q & A. XML basics. “well-formed” documents DTD D ocument T ype D efinition “valid” documents. Simple XML document. <?xml version="1.0"?>
E N D
XML case study: SyncML Sean C. Sullivan <sean> at <seansullivan> <.com>
Agenda • XML and SyncML • Sync4j project • Q & A
XML basics • “well-formed” documents • DTD • Document Type Definition • “valid” documents
Simple XML document <?xml version="1.0"?> <!DOCTYPE Weather SYSTEM “weather.dtd”> <Weather> <Forecast> <City>Portland, Oregon</City> <Description>Rainy</Description> <Temperature>47</Temperature> </Forecast> </Weather>
How are XML and SyncML related? • XML is a language for defining application-specific markup languages • SyncML is an XML-based markup language
<SyncML> <SyncHdr> <VerDTD>1.0</VerDTD> <VerProto>SyncML/1.0</VerProto> … </SyncHdr> <SyncBody> <Add>…</Add> </SyncBody> </SyncML> Simple SyncML document
SyncML defined… “SyncML is a new industry initiative to develop and promote a single, common data synchronization protocol that can be used industry-wide.” (syncml.org) “SyncML is a specification for a common data synchronization framework and XML-based format […] for synchronizing data on networked devices.” (syncml.org) “SyncML is a […] protocol for conveying data synchronization operations.” (syncml.org)
What is data synchronization? Data synchronization “is the process of making two sets of data look identical” (syncml.org whitepaper)
Datastore1 A B C • Exchange data modifications A B C A B C Data Synchronization Datastore2 • Resolve conflicts
What is a “data synchronization protocol”? • Method of communication for a data synchronization session • Protocol includes: • naming and identification of records • common protocol commands • identification and resolution of synchronization conflicts
SyncML features • Synchronize any type of data • Multiple transport protocol bindings • HTTP, WSP, OBEX • Security • Interoperability
server modifications client modifications SyncML: clients & servers SyncML server
SyncML & XML • Abbreviated naming convention • Ex: ”protocol version” is <VerProto> • XML prolog is not required • WBXML • WAPBinary XML
SyncML documents • <SyncML> DTD • Meta info DTD • Device info DTD
<?xml version="1.0"?> <!DOCTYPE … > <SyncML> <SyncHdr> … </SyncHdr> <SyncBody> <Add>…</Add> </SyncBody> </SyncML> “A SyncML Message is a well-formed, but not necessarily valid, XML document.” (syncml.org) Contains data synchronization commands (operations) <SyncML> document
<SyncHdr> element <SyncHdr> <VerDTD>1.0</VerDTD> <VerProto>SyncML/1.0</VerProto> <SessionID>session41</SessionID> <MsgID>msg80386</MsgID> … </SyncHdr>
<SyncBody> element <SyncBody> <Add> <CmdID>cmd80486</CmdID> … <Item>…</Item> </Add> </SyncBody>
SyncML commands • <Put> • <Replace> • <Results> • <Search> • <Sequence> • <Status> • <Sync> • <Add> • <Alert> • <Atomic> • <Copy> • <Delete> • <Exec> • <Get> • <Map>
Contains sync session parameters <MetInf> <Format>…</Format> <Type>…</Type> … <MaxMsgSize>586 </MaxMsgSize> … </MetInf> Meta Info document
Describes device capabilities For both client and server <DevInf> … <SwV>0.99</SwV> <HwV>3.14</HwV> … <DevTyp>pda</DevTyp> … </DevInf> Device Info document
Sync4j project • Java implementation of SyncML protocol • sync4j client & sync4j server • open source • http://sync4j.sourceforge.net/
XML parsing • SAX • “Simple API for XML” • DOM • document object model
Choosing an XML parser • support for SAX 1.0? SAX 2.0? • support for DOM? • support for XML Namespaces? • validating or non-validating parser? • validation with DTD’s? • validation with XML Schema?
XML parsers for Java • Apache Xerces-J • Apache Crimson • Sun JAXP • “Java API for XML Parsing” • JDOM • Also: • DOM4J, Oracle XML Parser for Java, ElectricXML, kxml, …
sync4j key classes • Message • DeviceInfo • MetaInfo • Command classes: • AddCommand • DeleteCommand • ReplaceCommand
Sync4j Message example 1 String strXML = “<SyncML> … </SyncML>”; Message msg; try { msg = new Message(strXML); } catch (InvalidMarkupException ex) { } catch (XMLSyntaxException ex) { }
Sync4j Message example 2 SyncHeader header = new SyncHeader(...); SyncBody body = new SyncBody(...); Message msg; msg = new Message(header, body); String strXML = msg.toXML();
XML data binding tools • Castor • http://www.castor.org/ • Zeus • http://zeus.enhydra.org/ • Sun JAXB • http://java.sun.com/xml/
Summary • SyncML is an XML-based data synchronization protocol • Choose your XML parser carefully • Consider using an XML data-binding tool • http://www.syncml.org/ • http://sync4j.sourceforge.net/
XML case study: SyncML Sean C. Sullivan <sean> at <seansullivan> <.com>