开发者

XElement.GetSchemaInfo() is returning null, Why?

I'm trying to validate an XDocument with a compiled schema that I have (which works) but when I try to access PSVI for the root XElement it returns null. I need this so I can validate child XElements.

Here is a sample code of what I'm trying to do:


XDocument xmlDoc = XDocument.Load(xmlFilePath);
XElement root开发者_StackOverflow中文版 = _xmlDoc.Elements().Single();
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(schema);
xmlDoc.Validate(schemas, ValidationEventHandler);
XmlSchemaElement se = xmlDoc.Elements().Single().GetSchemaInfo();

I can see that validation for XDocument works, I catch ValidationEvents and all.

All thoughts are appreciated. Thank you.


There's another overload for Validate (http://msdn.microsoft.com/en-us/library/bb354954(v=VS.90).aspx) which takes a boolean parameter. If you set that boolean to true, the PSVI will be stored on the nodes and then GetSchemaInfo should work. Without the PSVI in the tree it can't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜