简体   繁体   English

XML验证C#本地化

[英]XML Validation C# Localization

I am generating XML based upon some data. 我正在基于一些数据生成XML。 The culture is set to german, so the number is being generated in format 1087,1 (since in german they have commas instead of decimal). 区域性设置为德语,因此该数字以1087,1格式生成(因为德语中使用逗号而不是十进制)。 The problem is that when i try to validate the XML, the validation fails as it expects the number to be in English format (1087.1) and considers 1087,1 as string rather than number. 问题是,当我尝试验证XML时,验证失败,因为它期望数字为英文格式(1087.1),并认为1087,1是字符串而不是数字。

Is there a way we can validate in german number format? 有什么方法可以验证德国数字格式? OR Will I need to generate the XML in english number format? 或是否需要生成英文数字格式的XML? Following is the code i am using to validate XML 以下是我用来验证XML的代码

XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = xmlSchemaSet;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

// Create the XmlReader object.
XmlReader reader = XmlReader.Create("Test.xml", settings);

while (reader.Read())
{
     if (!isXmlValid)
       break;
}

Thanks! 谢谢!

If you want to rely on the built in data types (eg decimal) then it won't work for you simply because XSD's built-in lexical representation is by design culture invariant. 如果您要依靠内置的数据类型(例如十进制),那么它就不会简单地为您工作,因为XSD的内置词汇表示法在设计文化中是不变的。

If you wish to stick to the way your numbers are generated, then you have to go with an XSD that uses custom made data types, essentially based on xsd:string. 如果您希望坚持数字的生成方式,则必须使用XSD,该XSD使用基于xsd:string的定制数据类型。 The downside is that you're missing on standard bindings which would use strong types... 缺点是您缺少使用强类型的标准绑定...

Others may say to apply a transformation before consuming, basically interjecting custom processing to compensate for such lexical differences. 其他人可能会说在消费之前应用转换,基本上是通过插入自定义处理来补偿这种词汇差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM