.NET XML validator doesn’t give accurate error message for prohibited attributes

I am creating a validator in .NET8 for railML data format (based on XML) using XDocument.Validate() and XMLSchemaSet, but I encountered a situation when if I place an attribute in an element that, for example, doesn’t allow it or any attributes or doesn’t allow extensions from schemas in that place (doesn’t have xsi:any or xsi:anyAttribute etc) it provides an error message like this: “The ‘nameOfAttribute’ attribute is not declared.“.
In comparison if you place an incorrect child element, this is the kind of message I get:

The element ‘categories’ in namespace ‘http://www.railml.org/schemas/2011’ has invalid child element ‘track’ in namespace ‘http://www.railml.org/schemas/2011’. List of possible elements expected: ‘category’ in namespace ‘http://www.railml.org/schemas/2011’.

And it gives same error message even in the situation when the child element is an extension without declaration.

The problem is that when attribute’s schema or declaration is missing it gives the same kind of message as when it is not allowed, which also creates a situation when if I use an extension where I shouldn’t be able to and it is missing schema then it is not possible to tell difference between issue of declaration and it breaking the rules of railML. It is very important for me to know when attribute doesn’t belong to the element and the priority should be on that, instead of it being undeclared.

Here is the correct xml file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?xml version="1.0" encoding="UTF-8"?>
<railml xmlns="http://www.railml.org/schemas/2011"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.railml.org/schemas/2011 http://www.railml.org/schemas/2011/railML-2.1/railML.xsd"
version="2.1">
<timetable id="tt1">
<categories>
<category id="c1" code="IC" name="InterCity" description="Fast large city connection" trainUsage="passenger"/>
<category id="c2" code="RE" name="RegionalExpress" description="Fast small city connection" trainUsage="passenger"/>
</categories>
</timetable>
</railml>
</code>
<code><?xml version="1.0" encoding="UTF-8"?> <railml xmlns="http://www.railml.org/schemas/2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.railml.org/schemas/2011 http://www.railml.org/schemas/2011/railML-2.1/railML.xsd" version="2.1"> <timetable id="tt1"> <categories> <category id="c1" code="IC" name="InterCity" description="Fast large city connection" trainUsage="passenger"/> <category id="c2" code="RE" name="RegionalExpress" description="Fast small city connection" trainUsage="passenger"/> </categories> </timetable> </railml> </code>
<?xml version="1.0" encoding="UTF-8"?>
<railml xmlns="http://www.railml.org/schemas/2011" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.railml.org/schemas/2011 http://www.railml.org/schemas/2011/railML-2.1/railML.xsd" 
        version="2.1">
  <timetable id="tt1">
    <categories>
      <category id="c1" code="IC" name="InterCity" description="Fast large city connection" trainUsage="passenger"/>
      <category id="c2" code="RE" name="RegionalExpress" description="Fast small city connection" trainUsage="passenger"/>
    </categories>
  </timetable>
</railml>

Here is the changed part with incorrect attribute and child element in categories:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <timetable id="tt1">
> <categories id="c3">
<category id="c1" code="IC" name="InterCity" description="Fast large city connection" trainUsage="passenger"/>
<category id="c2" code="RE" name="RegionalExpress" description="Fast small city connection" trainUsage="passenger"/>
> <track id='tr_1' name='Some name' type='mainTrack'></track>
</categories>
</timetable>
</code>
<code> <timetable id="tt1"> > <categories id="c3"> <category id="c1" code="IC" name="InterCity" description="Fast large city connection" trainUsage="passenger"/> <category id="c2" code="RE" name="RegionalExpress" description="Fast small city connection" trainUsage="passenger"/> > <track id='tr_1' name='Some name' type='mainTrack'></track> </categories> </timetable> </code>
  <timetable id="tt1">
>     <categories id="c3">
      <category id="c1" code="IC" name="InterCity" description="Fast large city connection" trainUsage="passenger"/>
      <category id="c2" code="RE" name="RegionalExpress" description="Fast small city connection" trainUsage="passenger"/>
>       <track id='tr_1' name='Some name' type='mainTrack'></track>
    </categories>
  </timetable>

I also tested different validators, for example in Liquid Studio Microsoft .NET gives the same kind of declaration message, but Xerces actually tells “Critical cvc-complex-type.3.2.2: Attribute ‘id’ is not allowed to appear in element ‘categories’.“, which is more accurate to the situation. When I test same code in Altova XMLSpy it tells me this:

Attribute ‘id’ is not allowed in element ‘categories id=”c3″‘
Error location: railml / timetable / categories / @id
Details
cvc-complex-type.3.2.1: Complex type definition ‘rail:eCategories’ of element ‘categories id=”c3″‘ does not allow attribute ‘id’ and has no attribute wildcard.
cvc-type.3.2: Element categories id=”c3″ is not valid with respect to type definition ‘rail:eCategories’.
cvc-elt.5: The element categories id=”c3″ is not valid with respect to the actual type definition ‘rail:eCategories’.
cvc-assess-elt.1.1: Strict assessment of element categories id=”c3″ with governing element declaration ‘rail:categories’ failed.
Element ‘track id=”tr_1″‘ is not allowed under element ‘categories id=”c3″‘.
Reason: The following elements are expected at this location (see below)
‘rail:category’
Error location: railml / timetable / categories / track
Details
cvc-complex-type.1.4: Element ‘track id=”tr_1″‘ unexpected by type ‘rail:eCategories’ of element ‘categories id=”c3″.’

XMLSpy also notices difference between prohibited elements and undeclared, even if all of them are undeclared extensions.

Which is more like something I would expect.
So if attribute is places against railML rules it should always be noted as not allowed, even if it is something like undeclared extension. Is there any way to get similar result with adjusting/manipulating this approach with XDocument.Validate or with any other .NET validator? And what is the reason for such error message and why is there no difference between these two cases for .NET XDocument.Validate?

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật