Post on 12-Jan-2016
description
Copyright © 2002 Sean C. Sullivan
XML case study: XML case study: SyncMLSyncML
Sean C. Sullivan
<sean> at <seansullivan> <.com>
Copyright © 2002 Sean C. Sullivan
Agenda
XML and SyncML Sync4j project Q & A
Copyright © 2002 Sean C. Sullivan
XML basics
“well-formed” documents DTD
– Document Type Definition “valid” documents
Copyright © 2002 Sean C. Sullivan
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>
Copyright © 2002 Sean C. Sullivan
How are XML and SyncML related?
XML is a language for defining application-specific markup languages
SyncML is an XML-based markup language
Copyright © 2002 Sean C. Sullivan
Simple SyncML document<SyncML><SyncHdr><VerDTD>1.0</VerDTD><VerProto>SyncML/1.0</VerProto>…</SyncHdr><SyncBody><Add>…</Add></SyncBody></SyncML>
Copyright © 2002 Sean C. Sullivan
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)
Copyright © 2002 Sean C. Sullivan
SyncML sponsors
Copyright © 2002 Sean C. Sullivan
What is data synchronization?
Data synchronization “is the process of making two sets of data look identical” (syncml.org whitepaper)
Copyright © 2002 Sean C. Sullivan
Data Synchronization
Resolve conflicts
Datastore1
Exchange data modifications
Datastore2
A CB C A BA CB
Copyright © 2002 Sean C. Sullivan
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
Copyright © 2002 Sean C. Sullivan
SyncML features
Synchronize any type of data Multiple transport protocol bindings
– HTTP, WSP, OBEX Security Interoperability
Copyright © 2002 Sean C. Sullivan
SyncML: clients & servers
SyncMLserver
server modifications
client modifications
Copyright © 2002 Sean C. Sullivan
SyncML & XML
Abbreviated naming convention– Ex: ”protocol version” is <VerProto>
XML prolog is not required WBXML
– WAP Binary XML
Copyright © 2002 Sean C. Sullivan
SyncML documents
<SyncML> DTD Meta info DTD Device info DTD
Copyright © 2002 Sean C. Sullivan
<SyncML> document<?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)
Copyright © 2002 Sean C. Sullivan
<SyncHdr> element<SyncHdr>
<VerDTD>1.0</VerDTD>
<VerProto>SyncML/1.0</VerProto>
<SessionID>session41</SessionID>
<MsgID>msg80386</MsgID>
…
</SyncHdr>
Copyright © 2002 Sean C. Sullivan
<SyncBody> element<SyncBody>
<Add>
<CmdID>cmd80486</CmdID>
…
<Item>…</Item>
</Add>
</SyncBody>
Copyright © 2002 Sean C. Sullivan
SyncML commands <Add> <Alert> <Atomic> <Copy> <Delete> <Exec> <Get> <Map>
<Put> <Replace> <Results> <Search> <Sequence> <Status> <Sync>
Copyright © 2002 Sean C. Sullivan
Meta Info document
Contains sync session parameters
<MetInf><Format>…</Format><Type>…</Type>…<MaxMsgSize>586</MaxMsgSize>…</MetInf>
Copyright © 2002 Sean C. Sullivan
Device Info document
Describes device capabilities
For both client and server
<DevInf>
…
<SwV>0.99</SwV>
<HwV>3.14</HwV>
…
<DevTyp>pda</DevTyp>
…
</DevInf>
Copyright © 2002 Sean C. Sullivan
Sync4j project
Java implementation of SyncML protocol
sync4j client & sync4j server open source http://sync4j.sourceforge.net/
Copyright © 2002 Sean C. Sullivan
XML parsing SAX
– “Simple API for XML” DOM
– document object model
Copyright © 2002 Sean C. Sullivan
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?
Copyright © 2002 Sean C. Sullivan
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, …
Copyright © 2002 Sean C. Sullivan
sync4j key classes
Message DeviceInfo MetaInfo Command classes:
– AddCommand– DeleteCommand– ReplaceCommand
Copyright © 2002 Sean C. Sullivan
Sync4j Message example 1String strXML = “<SyncML> … </SyncML>”;Message msg;try{ msg = new Message(strXML);}catch (InvalidMarkupException ex){}catch (XMLSyntaxException ex){}
Copyright © 2002 Sean C. Sullivan
Sync4j Message example 2SyncHeader header = new SyncHeader(...);SyncBody body = new SyncBody(...);Message msg;msg = new Message(header, body);String strXML = msg.toXML();
Copyright © 2002 Sean C. Sullivan
XML data binding tools
Castor– http://www.castor.org/
Zeus– http://zeus.enhydra.org/
Sun JAXB– http://java.sun.com/xml/
Copyright © 2002 Sean C. Sullivan
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/
Copyright © 2002 Sean C. Sullivan
XML case study: XML case study: SyncMLSyncML
Sean C. Sullivan
<sean> at <seansullivan> <.com>