2009-12-16 4 views
2

나는 다음과 같은 XSD 파일이 있습니다
사용이 스키마

SchemaA

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema targetNamespace="http://schemaA" 
      elementFormDefault="qualified" 
      xmlns="http://schemaA" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
<xs:element name="Configuration"> 
    <xs:complexType> 
      <xs:all> 
       <xs:element name="StationNumber" type="xs:int"> 
       </xs:element> 
      </xs:all> 
    </xs:complexType> 
</xs:element> 
</xs:schema> 

SchemaB 내가 그들을 사용을 참조하기 위해 노력하고있어

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema targetNamespace="http://schemaB" 
      elementFormDefault="qualified" 
      xmlns="http://schemaB" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:attribute name="Name" type="xs:string" /> 
</xs:schema> 

을 다음 XML의 내용 :

<?xml version="1.0"?> 
<Configuration xmlns="http://schemaA" 
       xmlns:ba="http://schemaB"> 
    <StationNumber ba:Name="aaa">1</StationNumber> 
</Configuration> 

Visual Studio 2008 밑줄 ba : 설명과 함께 오류 이름 : 'http://schemaB:Name'특성이 선언되지 않았습니다.

아이디어가 있으십니까?

답변

2

이것은 두 스키마 문제가되지 않습니다, 당신의 스키마는 문서 내용과 일치하지 않습니다. 이름이 인 경우 구성에 가능한 속성 중 하나로 표시되지 않습니다.

전역 속성을 선언했기 때문에 원하는 곳 어디에서나 사용할 수 있다는 의미는 아닙니다. 하나의 스키마를 다른 스키마로 가져와야하고 위의 ewernli가 제공 한 첫 번째 응답과 마찬가지로 Configuration에 속성이 발생할 수 있도록 지정해야합니다.

<xs:element name="Configuration"> 
    <xs:complexType> 
    <xs:all> 
     <xs:element name="StationNumber" type="xs:int"/> 
    </xs:all> 
    <xs:anyAttribute namespace="http://schemaB"/> 
    </xs:complexType> 
</xs:element> 

변경 : 예를 들어

아니면 두 번째 네임 스페이스의 모든 속성이 첫 번째 스키마에 발생하는 허용, 제대로이 추가 문제가 있다고 지적 아래 ewernli에서 주석 다음 그 StationNumber는 단순한 유형입니다.유형을 준비하기 위해 속성을 준비하려면 다음을 수행해야합니다.

<xs:element name="Configuration"> 
    <xs:complexType> 
    <xs:all> 
     <xs:element name="StationNumber"> 
     <xs:complexType> 
      <xs:simpleContent> 
      <xs:extension base="xs:int"/> 
      </xs:simpleContent> 
     </xs:complexType> 
     </xs:element> 
    </xs:all> 
    <xs:anyAttribute namespace="http://schemaB"/> 
    </xs:complexType> 
</xs:element> 

이제 위에서 설명한대로 속성을 첨부 할 수 있습니다.

+0

고마워요! 지금은 훨씬 더 분명합니다! 아직 혼란스러운 점이 하나 있습니다! 다음 xml은 Visual Studio 2008에 따라 유효합니다. 두 번째 ns가 첫 xsd와 xsd가 다르며 두 번째 ns가 두 번째를 참조하지 않는다는 것을 100 % 확신합니다. 이 xml은 어떻게 유효합니까? 그것은 일종의 비주얼 스튜디오 컨벤션 및 표준 xsd 기능 아닌가요?

+0

불행히도 특정 스키마를 모르지만 Button 요소가 명령 네임 스페이스는 내 샘플에 표시된 것과 같은 방법입니까? – xcut

+0

단추 요소는 XAML과 관련된 공식 Microsoft 네임 스페이스에서 비롯되고 다른 네임 스페이스는 XAML (Microsoft의 새 UI 마크 업 언어)에 추가 기능으로 작동하는 프레임 워크에서 가져온 것이기 때문에 불가능하다고 생각합니다. 그런 애드온이있을 수 있습니다. XAML 용어에서 이러한 특성을 '첨부 된 속성'이라고합니다. – papadi

0

네임 스페이스에서 XSD를 찾을 수 있어야하며 불만이 있습니다. 인스턴스 문서에 schemaLocation을 사용하여 이것을 선언 할 수 있습니다.

+0

바 : Name 속성을 제외하고는 오류가 발생하지 않는다고해서 XSD가 이미 schemaLocation 없이도 위치한다는 것은 명백합니다. – papadi

1

요소 StationNumber에 schemaA에 속성이 없으면 <StationNumber ba:Name="...">...</StationNumber>이 유효하지 않습니다.

해결 방법 1은 : schemaAschemaB을 embedd 올바르게 속성 그런 다음 XML 다음 넷빈즈에 의해 검증 될 수

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema targetNamespace="http://schemaA" 
      elementFormDefault="qualified" 
      xmlns="http://schemaA" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
<xs:element name="Configuration"> 
    <xs:complexType> 
      <xs:all> 
       <xs:element name="StationNumber"> 
        <xs:complexType> 
         <xs:simpleContent> 
          <xs:extension base="xs:int"> 
           <xs:attribute name="Name" type="xs:string"/> 
          </xs:extension> 
         </xs:simpleContent> 
        </xs:complexType> 
       </xs:element> 
      </xs:all> 
    </xs:complexType> 
</xs:element> 
</xs:schema> 

정의 :

<ns2:Configuration xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
     xmlns:ns2='http://schemaA' 
     xsi:schemaLocation='http://schemaA file:/.../src/schemaA.xsd 
     http://xml.netbeans.org/schema/schemaB file:/.../schemaB.xsd'> 
       <ns2:StationNumber Name="aaa">1</ns2:StationNumber> 
    </ns2:Configuration> 

해결 방법 2 : 당신은 할 수 있습니다 여전히 속성을 정의하기 위해 별도의 schemaB이 있지만,로 가져와야합니다.ref로 :

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema targetNamespace="http://schemaA" 
      elementFormDefault="qualified" 
      xmlns="http://schemaA" 
      xmlns:ba='http://schemaB' 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

       <xs:import namespace="http://schemaB" 
       schemaLocation="schemaB.xsd"/> 

<xs:element name="Configuration"> 
    <xs:complexType> 
      <xs:all> 
       <xs:element name="StationNumber"> 
        <xs:complexType> 
         <xs:simpleContent> 
          <xs:extension base="xs:int"> 
           <xs:attribute ref="ba:Name"/> 
          </xs:extension> 
         </xs:simpleContent> 
        </xs:complexType> 
       </xs:element> 
      </xs:all> 
    </xs:complexType> 
</xs:element> 
</xs:schema> 

가 그런 다음 XML은 다음과 같습니다

<ns1:Configuration xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
    xmlns:ns1='http://schemaA' 
    xmlns:ba='http://schemaB' 
    xsi:schemaLocation='http://schemaA file:/.../schemaA.xsd'> 
    <ns1:StationNumber ba:Name="aaa" >1</ns1:StationNumber> 
</ns1:Configuration> 
관련 문제