2009-09-05 109 views
1

我有一種感覺這個XML是無效的,有人可以解釋爲什麼嗎?這是一個有效的XML嗎?

我認爲它有東西待辦事項點我的元素名稱?

estate_price.price_suggestion

其他任何事情對此XML無效?

XML

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

<iad> 
    <DataTag> 
    <element id="0"> 
     <changed_string>content</changed_string> 
     <no_of_bedrooms>content</no_of_bedrooms> 
     <published_string>content</published_string> 
     <mmo>content</mmo> 
     <postcode>content</postcode> 
     <utmx>content</utmx> 
     <utmy>content</utmy> 
     <disposed>content</disposed> 
     <property_type>content</property_type> 
     <isprivate>content</isprivate> 
     <heading>content</heading> 
     <published>content</published> 
     <estate_price.price_suggestion>content</estate_price.price_suggestion> 
     <ownership_type>content</ownership_type> 
     <estate_size.useable_area>content</estate_size.useable_area> 
     <adid>content</adid> 
     <address>content</address> 
     <sqmtrprice>content</sqmtrprice> 
     <estate_size.primary_room_area>content</estate_size.primary_room_area> 
     <location>content</location> 
     <changed>content</changed> 
     <orgname>content</orgname> 
    </element> 
    <element id="1"> 
     <changed_string>content</changed_string> 
     <no_of_bedrooms>content</no_of_bedrooms> 
     <published_string>content</published_string> 
     <mmo>content</mmo> 
     <postcode>content</postcode> 
     <utmx>content</utmx> 
     <utmy>content</utmy> 
     <disposed>content</disposed> 
     <property_type>content</property_type> 
     <isprivate>content</isprivate> 
     <heading>content</heading> 
     <published>content</published> 
     <estate_price.price_suggestion>content</estate_price.price_suggestion> 
     <ownership_type>content</ownership_type> 
     <estate_size.useable_area>content</estate_size.useable_area> 
     <adid>content</adid> 
     <address>content</address> 
     <sqmtrprice>content</sqmtrprice> 
     <estate_size.primary_room_area>content</estate_size.primary_room_area> 
     <location>content</location> 
     <changed>content</changed> 
     <orgname>content</orgname> 
    </element> 
    </DataTag> 
</iad> 

回答

2

我們需要確認您正在驗證的模式,以告訴您文檔是否有效。

作爲XML規範禁止使用的元素名稱,沒有關於estate_price.price_suggestion的信息,但是您的模式可能會對您的文檔內容和結構施加約束,但不允許該元素(或任何其他元素)放在它的位置。

6

有良好的XML文檔的兩個層次:well-formed和有效。格式良好意味着您遵守XML標準,並且有效意味着您符合架構。

架構是一個規範,你正在使用哪些元素,什麼可以進入另一個。你可以使用DTD,XSD(W3C Schema),Relax NG等來指定模式。

1

Dave Markle是正確的,因爲您的XML prolog不應該有反斜槓前綴(另請注意,它是可選的,因爲它只提供默認的prolog值)。

至於元素名稱中的點,如果你去to the XML spec for start tags你會看到它包含一個Name,它本身由一個NameStartChar和一個NameChar序列組成。 NameChar集恰好包含字符「。」,因此在標籤名中有.只要它不是第一個字符就是完全有效的。

0

您的XML格式良好,應該在任何非驗證XML解析器中進行解析。比如我用XOM(從http://www.xom.nu

 try { 
     new nu.xom.Builder().build(new StringReader(s)); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    System.out.println("OK"); 

但是也有一些XML工具,這使得關於屬性的類型假設。 id屬性MIGHT被假定爲ID類型。此類型將id值限制爲只能以_A-Za-z(不是'0-9',' - '或'。')開頭的有效XML名稱。因此,雖然您的XML格式良好,但使用ID號碼可能是一個糟糕的主意。正如已經指出的那樣,如果你有一個DTD或模式,那麼這個id可能被強制爲ID類型,這會導致驗證失敗。

從您的帖子中不清楚您是否已經有問題 - 如果發佈錯誤消息可能會有所幫助。