2009-09-14 109 views
2

我想驗證以下XML,但我無法修復,請您發現錯誤?XML驗證錯誤

<!-- menu: its a menu --> 
<menu id="Welcome"> 
    <!--audio: file to play --> 
    <audio src="D:\Telephony\VOXs\Welcome.vox" /> 
</menu> 

<!-- form: its a menu --> 
<menu id="LanguageSelection"> 
    <audio src="D:\Telephony\VOXs\LanguageSelection.vox" /> 

    <input timeout="5" max_timeout="2" max_invalid_input="2" valid_dtmfs="1, 2"> 

     <!-- noinput: if timeout occurred, execute this --> 
     <noinput> 
      <audio src="D:\Telephony\VOXs\Timeout.vox" /> 
     </noinput> 

     <!-- nomatch: if wrong dtmf given, following will execute --> 
     <nomatch> 
      <audio src="D:\Telephony\VOXs\InvalidInput.vox" /> 
     </nomatch> 

     <switch> 
      <dtmf-1> 
       <audio src="D:\Telephony\VOXs\EnglishSelected.vox" /> 
      </dtmf-1> 

      <dtmf-2> 
       <audio src="D:\Telephony\VOXs\UrduSelected.vox" /> 
      </dtmf-2> 
     </switch> 
    </input> 
</menu> 

<menu id="MainMenu"> 
    <audio src="D:\Telephony\VOXs\MainMenu.vox" /> 

    <input timeout="5" max_timeout="2" max_invalid_input="2" valid_dtmfs="1, 2"> 

     <!-- noinput: if timeout occurred, execute this --> 
     <noinput> 
      <audio src="D:\Telephony\VOXs\Timeout.vox" /> 
     </noinput> 

     <!-- nomatch: if wrong dtmf given, following will execute --> 
     <nomatch> 
      <audio src="D:\Telephony\VOXs\InvalidInput.vox"/> 
     </nomatch> 

     <switch> 
      <dtmf-1> 
       <goto menu="InformationMenu" /> 
      </dtmf-1> 

      <dtmf-2> 
       <goto menu="SupportMenu" /> 
      </dtmf-2> 
     </switch> 
    </input> 
</menu> 

我在驗證Validome.org時出現以下錯誤。

錯誤:根元素後面的文檔中的標記必須格式良好。

錯誤位置:< ENU ID = 「語言選擇」>

回答

2

您有多於一個頂級元素<menu>

請嘗試以下操作。我添加了<MenuItems>作爲頂級元素,並在最後關閉它。

<MenuItems> 
<!-- menu: its a menu --> 
<menu id="Welcome"> 
    <!--audio: file to play --> 
    <audio src="D:\Telephony\VOXs\Welcome.vox" /> 
</menu> 

<!-- form: its a menu --> 
<menu id="LanguageSelection"> 
    <audio src="D:\Telephony\VOXs\LanguageSelection.vox" /> 

    <input timeout="5" max_timeout="2" max_invalid_input="2" valid_dtmfs="1, 2"> 

     <!-- noinput: if timeout occurred, execute this --> 
     <noinput> 
       <audio src="D:\Telephony\VOXs\Timeout.vox" /> 
     </noinput> 

     <!-- nomatch: if wrong dtmf given, following will execute --> 
     <nomatch> 
       <audio src="D:\Telephony\VOXs\InvalidInput.vox" /> 
     </nomatch> 

     <switch> 
       <dtmf-1> 
         <audio src="D:\Telephony\VOXs\EnglishSelected.vox" /> 
       </dtmf-1> 

       <dtmf-2> 
         <audio src="D:\Telephony\VOXs\UrduSelected.vox" /> 
       </dtmf-2> 
     </switch> 
    </input> 
</menu> 

<menu id="MainMenu"> 
    <audio src="D:\Telephony\VOXs\MainMenu.vox" /> 

    <input timeout="5" max_timeout="2" max_invalid_input="2" valid_dtmfs="1, 2"> 

     <!-- noinput: if timeout occurred, execute this --> 
     <noinput> 
       <audio src="D:\Telephony\VOXs\Timeout.vox" /> 
     </noinput> 

     <!-- nomatch: if wrong dtmf given, following will execute --> 
     <nomatch> 
       <audio src="D:\Telephony\VOXs\InvalidInput.vox"/> 
     </nomatch> 

     <switch> 
       <dtmf-1> 
         <goto menu="InformationMenu" /> 
       </dtmf-1> 

       <dtmf-2> 
         <goto menu="SupportMenu" /> 
       </dtmf-2> 
     </switch> 
    </input> 
</menu> 
</MenuItems> 

您可以通過在ie中打開來快速檢查ur xml。當我打開你的xml時,這就是我得到的。

Only one top level element is allowed in an XML document. Error processing resource 'file://Users/shoban/... 

<menu id="LanguageSelection"> 
-^ 
+0

你能解釋一下發生了什麼問題嗎?爲什麼?以及如何解決? – akif 2009-09-14 11:57:37

+1

編輯答案。現在檢查它是否清楚。 – Shoban 2009-09-14 11:59:20

+0

完美,謝謝! – akif 2009-09-14 12:02:53

2

您需要一個根級元素。例如,將菜單元素包裝在<menus>標記中。

<menus> 
    <menu> 
    </menu> 
    <menu> 
    </menu> 
</menus> 
1

Well-formedness

SUMMARY:

The XML specification defines an XML document as a text which is well-formed, i.e., it satisfies a list of syntax rules provided in the specification. The list is fairly lengthy; some key points are:

  1. It contains only properly-encoded legal Unicode characters.
  2. None of the special syntax characters such as "<" and "&" appear except when performing their markup-delineation roles.
  3. The begin, end, and empty-element tags which delimit the elements are correctly nested, with none missing and none overlapping.
  4. The element tags are case-sensitive; the beginning and end tags must match exactly.
  5. There is a single "root" element which contains all the other elements.
1

您的問題的根本原因是,你的XML文檔每個文件不止一個根元素。

在您的特定情況下的文檔的基本結構是:

<menu></menu> 
<menu></menu> 
<menu></menu> 

即定義文檔中3個元素。

爲了定義需要圍繞一個單一的根元素的三個要素如下的單個元素:

<menus> 
    <menu></menu> 
    <menu></menu> 
    <menu></menu> 
</menus> 

你可以找到更多在這個simple tutorial I found