2017-07-19 8 views
0

XmlDocumentを使用してXmlファイルを検証するルーチンをC#で作成しています。私は理解できない何かを除いてすべてがうまくいくようです。XSDエラーに対するXMLの検証:無効なxsi:タイプ

私のxml:

<?xml version="1.0" encoding="utf-8"?> 
<bdo_fosfec:RegistrosPagosElement xsi:type="bdo_fosfec:RegistrosPagos" 
xmlns:bdo_fosfec="http://asocajas.hp.com/bdo_fosfec" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<registro54 xsi:type="bdo_fosfec:Registro54"> 
    <registro82 xsi:type="bdo_fosfec:Registro82"> 
    ... 
    </registro82> 
</registro54> 
<registro54 xsi:type="bdo_fosfec:Registro54"> 
    <registro82 xsi:type="bdo_fosfec:Registro82"> 
    ... 
    </registro82> 
</registro54> 
</bdo_fosfec:RegistrosPagosElement> 

およびxsd:ここ

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns="http://asocajas.hp.com/bdo_fosfec" xmlns:tns1="http://asocajas.hp.com/bdo_fosfec" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://asocajas.hp.com/bdo_fosfec"> 
    <xsd:annotation> 
<xsd:documentation>BOMORIGIN::platform:/resource/bdo_Fosfec/Business%20Objects/bdo_Fosfec.bom#_rs4Sa9itEeSR9aIqvSWzoQ</xsd:documentation> 
    </xsd:annotation> 
    ... 
</xsd:schema> 

は、XSDに対する私のXMLを検証するための私のコードです

XmlDocument xml = new XmlDocument(); 
xml.Schemas.Add("http://asocajas.hp.com/bdo_fosfec", PathFileXSD); 
//load my xml 
xml.LoadXml(stringXml); 

//event handler to manage the errors from XmlDocument object 
ValidationEventHandler veh = new ValidationEventHandler(ErrorValidacion); 

//validate my xml 
xml.Validate(veh); 

とイベントハンドラErrorValidacionが表示されます私のエラー

private void ErrorValidacion(object sender, ValidationEventArgs e) 
{ 
    string concat = string.Empty; 
    switch (e.Severity) 
    { 
     case XmlSeverityType.Error: 
      concat = string.Format("Error: {0}", e.Message); 
      break; 
     case XmlSeverityType.Warning: 
      concat = string.Format("Warning {0}", e.Message); 
      break; 
    } 
} 

エラーMSJがある私のプログラムを実行すると:私のxmlの型にxsiない

http://asocajas.hp.com/bdo_fosfec:RegistrosPagos

です:このメッセージは?XSIはなぜ..

This is an invalid xsi:type ' http://asocajas.hp.com/bdo_fosfec:RegistrosPagos '.

ものは次のとおりです。タイプhttp://asocajas.hp.com/bdo_fosfec:RegistrosPagosから来る:私のXMLのタイプでは、xsiはない

xsi:type="bdo_fosfec:RegistrosPagos"

のですか?

xmlを変更することなくこの問題を解決するにはどうすればよいですか? (xmlはxsltに基づいているため)

答えて

0

XSDには、http://asocajas.hp.com/bdo_fosfec名前空間にRegistrosPagosの宣言が含まれていないというエラーメッセージが表示されます。

名前空間のプレフィックスは任意であり、定義上意味がないため、名前空間の拡張形式を使用してエラーを報告します。これは完全に適切です。

実際に投稿したXSDには、http://asocajas.hp.com/bdo_fosfec名前空間にRegistrosPagosが含まれていません。

も参照してください:How to restrict the value of an XML element using xsi:type in XSD?

関連する問題