나는 나의 XSD 스키마에 대해 일부 외부 XML 문서의 유효성을 확인 :XmlDocument 유효성 검사가 다른 네임 스페이스가있는 xml에 예외를 throw하지 않는 이유는 무엇입니까?
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2011-03-01">
<xs:element name="Document" type="DocumentType" />
<xs:complexType name="DocumentType">
<xs:sequence>
<xs:element name="Author" type="string" minOccurs="0" />
<xs:element maxOccurs="unbounded" name="Receiver" type="string" />
</xs:sequence>
</xs:complexType>
내 스키마 네임 스페이스를 사용하지 않습니다. 잘 작동하지만 특정 XML에 문제가 있습니다. XLM으로 저장된 파일입니다. 그것은 완전히 무효이지만 유효성 검사기는 불평하지 않습니다. 내 스키마에 따라 유효하지 않지만 내 메서드가 예외를 throw하지 않습니다! 여기
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content
xmlns:office="foo">
<office:bar></office:bar>
</office:document-content>
을 내 코드는 다음과 같습니다 : 그것은 다음과 같습니다
public void Validate(Stream streamWithXML)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(settings.Schemas.Add("", xsdPath));
settings.ValidationType = ValidationType.Schema;
XmlReader reader = XmlReader.Create(streamWithXML, settings);
XmlDocument document = new XmlDocument();
document.Load(reader);
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
document.Validate(eventHandler);
reader.Close();
}
static void ValidationEventHandler(object sender, ValidationEventArgs e)
{}
당신이 어떤 단서를 가지고 있습니까? 특정 문서에 인라인 네임 스페이스 선언이 있기 때문입니다. '문서 내용 사무실'
이 요소 의 선언을 찾을 수 없습니다 : http://tools.decisionsoft.com/schemaValidate/에서 그러나 온라인 검사기는 예외가 발생합니다.
올바른 내용입니다. 이 경우에 .NET Validator가 예외를 발생시킬 수있는 방법이 있습니까?
안녕하세요, Jip .. 저는 잠시 동안 알고 있지만 최종 해결책을 업데이트 할 수 있습니까? 동일한 문제가 있으며 해결 방법을 찾을 수 없습니다. – lawphotog