2011-12-13 32 views
6

Tôi mới dùng ngôn ngữ xml, tôi có một tệp xml và tôi đã tạo giản đồ xsd cho tệp đó, nhưng vấn đề của tôi là cách tham chiếu lược đồ này trong tệp xml. Lược đồ xml của tôi trông giống như thế nàytham chiếu tệp xsd trong xml

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:wmh="http://www.wmhelp.com/2003/eGenerator" 
    elementFormDefault="qualified" 
    targetNamespace="http://axis.com/service" 
    xmlns="http://axis.com/service" 
    version="1.0"> 

    <xs:element name="SWService" type="SWServiceType"/> 
    <xs:element name="HWService" type="HWServiceType"/> 


<xs:complexType name="SWServiceType"> 
<xs:sequence> 
    <xs:element name="Service" type="ServiceType" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:sequence> 
    </xs:complexType> 

<xs:complexType name="ServiceType"> 
<xs:complexContent> 
<xs:extension base="IdType"> 
    <xs:sequence> 
    <xs:element name="Description" type="xs:string" maxOccurs="1" minOccurs="0"/> 
    <xs:element name="ServiceCustomers" type="ServiceCustomersType" maxOccurs="1" 
minOccurs="0"/> 
    <xs:element name="ServiceSuppliers" type="ServiceSuppliersType" maxOccurs="1" 
minOccurs="0"/> 
    </xs:sequence> 
    <xs:attribute name="Name" type="xs:string" use="required"/> 
    </xs:extension> 
    </xs:complexContent> 
    </xs:complexType> 

    <xs:complexType name="HWServiceType"> 
    <xs:sequence> 
    <xs:element name="element" type="elementGroupType" maxOccurs="1" minOccurs="0"/> 
    </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="ServiceCustomersType"> 
    <xs:sequence> 
    <xs:element name="SoftWare" type="SoftWareType" maxOccurs="unbounded" 
    minOccurs="0"/> 
    </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="ServiceSuppliersType"> 
    <xs:sequence> 
    <xs:element name="SoftWare" type="SoftWareType" maxOccurs="unbounded" 
minOccurs="0"/> 
    <xs:element name="HardWare" type="HardWareType" maxOccurs="unbounded" 
    minOccurs="0"/> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="SoftWareType"> 
<xs:complexContent> 
<xs:extension base="PathType"> 
    <xs:attribute name="Service" type="xs:string" use="required"/> 
    </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 

<xs:complexType name="HardWareType"> 
<xs:complexContent> 
<xs:extension base="PathType"> 
    <xs:attribute name="Type" type="xs:string" use="required"/> 
    <xs:attribute name="Nr" type="xs:string" use="required"/> 
    <xs:attribute name="Service" type="xs:string" use="required"/> 
    </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 

<xs:complexType name="PathType"> 
    <xs:attribute name="Path" type="xs:string" use="required"/> 
</xs:complexType> 


    <xs:complexType name="elementGroupType"> 
<xs:sequence> 
     <xs:element name="element" type="elementType" maxOccurs="unbounded" 
minOccurs="1"/> 
    </xs:sequence> 
</xs:complexType> 


<xs:complexType name="elementType"> 
    <xs:sequence> 
    <xs:element name="LM" type="LMType2" maxOccurs="1" minOccurs="1"/> 
    <xs:element name="Service" type="ServiceType" maxOccurs="unbounded" minOccurs="0"/> 
    </xs:sequence> 
    <xs:attribute name="Type" type="xs:string" use="required"/> 
    <xs:attribute name="Nr" type="xs:string" use="required"/> 
    <xs:attribute name="Name" type="xs:string" use="required"/> 
</xs:complexType> 


    <xs:complexType name="LMType2"> 
    <xs:sequence> 
    <xs:element name="LowerMode" type="LowerModeType2" maxOccurs="unbounded" 
minOccurs="0"/> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="LowerModeType2"> 
<xs:complexContent> 
    <xs:extension base="IdType"> 
    <xs:attribute name="Probability" type="xs:double" use="required"/> 
    </xs:extension> 
    </xs:complexContent> 
    </xs:complexType> 


<xs:complexType name="IdType"> 
    <xs:attribute name="Id" type="xs:string" use="required"/> 
</xs:complexType> 

    </xs:schema> 

Tôi đã lưu tệp này dưới dạng service.xsd. Tôi cần tham chiếu lược đồ này trong tệp xml của mình, tôi đã thử như thế này nhưng không xác thực.

<?xml version="1.0" encoding="UTF-8"?> 
<Service xsi:schemaLocation="file:///C:/main/newfolder/service.xsd"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service"   
Version="1.0"> 
--------Xml data------- 
</Service> 

Tôi không thể giải quyết được vấn đề. Nó cung cấp cho lỗi như thế này

No DTD of the document found 

tôi đã cố gắng như cùng một vấn đề

<?xml version="1.0" encoding="UTF-8"?> 
<Service xsi:schemaLocation=""http://axis.com/service"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service"   
Version="1.0"> 
--------Xml data------- 
</Service> 

nhưng vẫn này. khi tôi xác thực tệp xml bằng xmlpad. Bất kỳ ai cũng có thể khắc phục sự cố của tôi. Chúng tôi giúp đánh giá cao

Cảm ơn bạn trước.

+1

+1: Một trong những bài đăng đầu tiên tốt nhất tôi đã xem trong một thời gian! –

+0

Bạn có thể mô tả cách bạn đang xác nhận hợp lệ XML không? Bạn có sử dụng một số chương trình bên ngoài hoặc có thể với một số thư viện? – bbaja42

+0

@ bbaja42 Tôi đang xác thực bằng XMLPAD. – user234

Trả lời

1

Việc sử dụng schemaLocation là hoàn toàn tùy chọn và phiên bản thuộc tính là không chính xác trong trường hợp của bạn (trừ khi bạn đã xác định một thuộc tính gọi là Version trong lược đồ)

Các ví dụ sau đây

<Service xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service"> 
any string 
</Service> 

Xác nhận tốt chống lại lược đồ:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:wmh="http://www.wmhelp.com/2003/eGenerator" 
    elementFormDefault="qualified" 
    targetNamespace="http://axis.com/service" 
    xmlns="http://axis.com/service" 
    version="1.0"> 
    <xs:element name="Service" type="xs:string"/> 
</xs:schema> 

Tất cả những gì tôi đã làm là thay thế loại AxisServiceType bằng chuỗi.

Để xác định nguyên nhân chính xác của lỗi mà bạn gặp phải, tôi cần xem toàn bộ lược đồ và tài liệu ví dụ của bạn.

+0

Cảm ơn câu trả lời của bạn, tôi viết một xsd cho các định dạng tệp xml khác nhau, SWService, HWService, ModuleSpecification liên quan đến các tệp xml khác nhau và tệp xS của SWService xml được tham chiếu theo SWServiceType.like thông minh cho ba tệp xml khác nhau. Tôi đã chỉnh sửa bài đăng của mình có thể xem bài đăng đã chỉnh sửa của tôi. Tôi cần tham khảo xsd này trong ba định dạng tệp xml khác nhau. bạn có thể giúp tôi như thế. Nếu tôi tham khảo xsd này mà không có không gian tên xác nhận của nó, nhưng với không gian tên nó cho lỗi. – user234

+0

Tôi xin lỗi nhưng bạn sẽ phải cung cấp cho tôi toàn bộ lược đồ XSD để tôi có thể giúp bạn xây dựng một tài liệu XML thể hiện. –

+0

Bạn có thể xem xsd của tôi không, tôi đã cung cấp toàn bộ lược đồ xsd. – user234

Các vấn đề liên quan