2011-04-18 32 views
0

我正在製作與服務器同步資源的移動應用程序。這將有以下行爲:我應該使用什麼格式的列表來同步文件?

  • 有所有文件的服務器上的列表
  • 有其中遠程文件將被存儲在本地的值
  • 這裏有一個校驗和比較本地列表以查看遠程文件是否已更改
  • 優選地,文件應該被加密。 (但當然我們可以使用https)

我首先想到了最簡單的解決方案,使用CSV來存儲值。然後我們考慮了該程序的可擴展性,並得出結論認爲XML會更開放。我做了一些Google搜索,沒有找到符合我們目的的模式。 RSS,ATOM對我們的一些要求不足,XDI看起來太複雜。

我們應該製作自己的XML模式嗎?還是有一些簡單的和默認的格式,將適合我們的情況。

謝謝!

回答

我做了一個自定義的XML架構對於這一點,在這裏它是其他任何人蔘考。

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<!--Simple Types--> 
<xs:simpleType name="remoteurltype"> 
    <xs:restriction base="xs:anyURI"> 
    <xs:pattern value="http(s)?://.*"/> 
    </xs:restriction> 
</xs:simpleType> 

<xs:simpleType name="localurltype"> 
    <xs:restriction base="xs:anyURI"> 
    <xs:pattern value="/.*"/> 
    </xs:restriction> 
</xs:simpleType> 

<xs:simpleType name="dectype"> 
    <xs:restriction base="xs:decimal"> 
    <xs:pattern value="[0-9]+\.?[0-9]*"/> 
    </xs:restriction> 
</xs:simpleType> 

<xs:simpleType name="hashtype"> 
    <xs:restriction base="xs:string"> 
    <xs:pattern value="[a-z0-9]{32}"/> 
    </xs:restriction> 
</xs:simpleType> 

<!-- Complex Types --> 
<xs:complexType name="resourcetype"> 
    <xs:attribute name="src" type="remoteurltype" use="required"/> 
    <xs:attribute name="local" type="localurltype" use="required"/> 
    <xs:attribute name="hash" type="hashtype" use="required"/> 
</xs:complexType> 

<xs:complexType name="resourcelisttype"> 
    <xs:sequence> 
    <xs:element name="db" type="resourcetype"/> 
    <xs:element name="img" maxOccurs="unbounded" type="resourcetype"/> 
    </xs:sequence> 
    <xs:attribute name="version" type="dectype" use="required"/> 
</xs:complexType> 

<!-- Root Element --> 
<xs:element name="resources" type="resourcelisttype"/> 

</xs:schema> 

這是很好的驗證,這裏是一個例子。

<?xml version="1.0" encoding="UTF-8"?> 

<resources version="0.5" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="resources.xsd"> 
    <db src="http://prdownloads.sourceforge.net/souptonuts/sqlite_examples.tar.gz?download" 
    local="/database/default.sqlite" hash="64846a8f75d56fd68b01f55495ac5986" /> 
    <img src="http://www.google.com/images/logos/ps_logo2.png" 
    local="/images/google.png" hash="4b9606a40bd81e8a047d2f74fa167e35" /> 
    <img src="http://www.baidu.com/img/baidu_sylogo1.gif" 
    local="/images/baidu_sylogo1.gif" hash="52137eafacaf179057c837dfa720ecf9" /> 
</resources> 

回答

1

您應該爲此使用自己的XML模式。新架構的設計和實現很容易可能是使用XML的主要優勢。

遠離CSV,因爲它將成爲字符集,嵌入式引號,嵌入式新行等常見問題的根源。

相關問題