다음과 같은 XML 파일이 있습니다.XSD 기본 도움말 필요 - 스키마의 네임 스페이스?
<credits>
<property name="tag">
<item>v0003</item>
</property>
<property
name="tag">
<item>mhma03h</item>
</property>
</credits>
첫 번째 요구 사항이 XML은 상관없이 변경할 수 없습니다 이다. 아래에서 그렇게하지 않는 것이 좋습니다.
이 유효성을 검사하는 스키마를 작성해야합니다. 그리고 검증을 수행하는 Java 코드.
나는 완전히 붙어있어 실제로 어떤 일이 벌어지고 있는지 전혀 모른다.
다음과 같은 스키마는 무엇입니까? 나는 그것을 얻었지만 너무 나쁘다 나는 게시하는 것을 괴롭히지 않을 것이다. : XML 요소에 네임 스페이스를 추가하지 않아도됩니다. 그것들은 돌로 세팅되어 있습니다.^_^
어떻게하면이 모든 요소들이 파서에 의해 "발견"되었습니까? 나는이 모든 네임 스페이스를 무시한다고 말할 수 있을까요? 스키마에 대해 유효성을 검사하는이 응용 프로그램을 사용하면 네임 스페이스 충돌을 간단하게 해결할 수 없습니다. 내가 지금까지 주어진 답을 반영하기 위해 뭘하는지 업데이트 한을 :
내 네임 스페이스 정보를
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="books" elementFormDefault="unqualified">
및
UPDATE 퍼팅 시도했습니다! :)
로드 예 검증 XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="property">
<xs:complexType>
<xs:sequence>
<xs:element ref="item"/>
</xs:sequence>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="tag"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="mhma03h"/>
<xs:enumeration value="v0003"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="credits">
<xs:complexType>
<xs:sequence>
<xs:element ref="property" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML v0003
코드입니다. 질문하기 전에 파일을에로드 할 수 있습니다. 나는 20 번 검사했다. : P
여기SAXParserFactory factory = SAXParserFactory.newInstance();
SchemaFactory schemaFactory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
factory.setSchema(schemaFactory.newSchema(
new Source[] {new StreamSource("small.xsd")}));
javax.xml.parsers.SAXParser parser = factory.newSAXParser();
org.xml.sax.XMLReader reader = parser.getXMLReader();
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
reader.parse(new InputSource("small.xml"));
내 Java 유효성 검사 코드를 통해 스키마를 실행하여이 예외가 발생합니다. cvc-elt.1 : 'xs : schema'요소의 선언을 찾을 수 없습니다.SAXParser 객체에 설정해야하는 특정 설정이나 무언가가 실패하지 않습니까? – bobber205
이 오류는 .xsd를 넣어야하는 .xsd를 넣었 기 때문에 발생했습니다. – bobber205