jjzjj

XmlReaderSettings

全部标签

c# - ExecuteXmlReaderAsync 未按预期工作

我正在尝试使用.NET4.5中的新异步方法从MSSQL读取XML。我有以下代码varxmlReader=awaitsqlCommand.ExecuteXmlReaderAsync();while(awaitxmlReader.ReadAsync()){vardoc=(MyDocument)xmlSerializer.Deserialize(xmlReader);awaitProcess(doc);}如果您想使用异步方法,它会因SetXmlReaderSettings.Asynctotrue而失败。。我检查了ExecuteXmlReaderAsync的反编译源,我可以看到它使用了以下设置

xml - .net 3.5 中的 DtdProcessing.Ignore

在.net4.0中,我们可以使用属性XmlReaderSettings.DtdProcessing和值DtdProcessing.Ignore来忽略dtd。在.net3.5中,我们只能使用没有忽略值的XmlReaderSettings.ProhibitDtd。如何在.net3.5中为dtd激活忽略模式? 最佳答案 尝试以下操作:XmlReaderSettings.ProhibitDtd=false;XmlReaderSettings.XmlResolver=null;XmlDocument.XmlResolver=null;对我有用

c# - 无法在 XmlTextReader 上进行设置?

我需要在XmlTextReader上设置MaxCharactersFromEntities,这是我目前的代码:xmlDocument=newXmlDocument();xmlTextReader=newXmlTextReader(fileInfo.FullName);xmlTextReader.Settings=newXmlReaderSettings();xmlTextReader.Settings.MaxCharactersFromEntities=0;varvr=newXmlValidatingReader(xmlTextReader);vr.ValidationType=Val

c# - 在 C# 中使用本地 DTD 文件验证 XML 文件时出现问题

我正在尝试验证XML文件。我正在使用这段代码XmlReaderSettingssettings=newXmlReaderSettings();settings.ProhibitDtd=false;settings.ValidationType=ValidationType.DTD;settings.ValidationEventHandler+=newValidationEventHandler(validationError);XmlSchemaSetschemas=newXmlSchemaSet();settings.Schemas=schemas;XmlReaderreader=

c# - 如何在 .net 反序列化期间防止 XML 外部实体 (XXE) 攻击

我们正在使用veracode对我们的代码进行安全分析,它显示了以下代码的XXE漏洞,特别是在调用Deserialize()的地方。我们如何防止序列化程序访问外部实体。我在下面为XMLReader将XMLresolver设置为null的尝试不起作用。publicstaticTDeserializeObject(stringxml,stringNamespace){System.Xml.Serialization.XmlSerializerserializer=newSystem.Xml.Serialization.XmlSerializer(typeof(T),Namespace);Me

c# - 添加(嵌入式资源)架构到 XmlReaderSettings 而不是文件名?

我正在编写一个解析Xml文件的应用程序。我有模式(.xsd)文件,我在尝试反序列化之前使用它来验证Xml:XmlReaderSettingssettings=newXmlReaderSettings();settings.Schemas.Add(null,"./xml/schemas/myschema.xsd");settings.ValidationType=ValidationType.Schema;XmlReaderreader=XmlReader.Create(xmlFile,settings);XmlDocumentdocument=newXmlDocument();docu

c# - .NET : How to validate XML file with DTD without DOCTYPE declaration

我有一个没有DOCTYPE声明的XML文件,我想在阅读时使用外部DTD对其进行验证。Dimx_setAsXml.XmlReaderSettings=NewXml.XmlReaderSettings()x_set.XmlResolver=Nothingx_set.CheckCharacters=Falsex_set.ProhibitDtd=Falsex=XmlTextReader.Create(sChemin,x_set)如何设置外部DTD的路径?你如何验证? 最佳答案 下面的功能我之前用过,应该很容易适应。如magnifico所述,

c# - 使用 XSD 架构的 Xml 验证

以下代码帮助我验证具有XSD架构的XML文件。XmlReaderSettingssettings=newXmlReaderSettings();settings.Schemas.Add(null,xsdFilePath);settings.ValidationType=ValidationType.Schema;settings.ValidationEventHandler+=newSystem.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler);XmlDocumentdocument=newXmlDoc

c# - xml 文档异常中禁止 DTD

尝试解析C#应用程序中的XML文档时出现此错误:"ForsecurityreasonsDTDisprohibitedinthisXMLdocument.ToenableDTDprocessingsettheProhibitDtdpropertyonXmlReaderSettingstofalseandpassthesettingsintoXmlReader.Createmethod."作为引用,异常发生在以下代码的第二行:using(XmlReaderreader=XmlReader.Create(uri)){reader.MoveToContent();//herewhile(rea

c# - xml 文档异常中禁止 DTD

尝试解析C#应用程序中的XML文档时出现此错误:"ForsecurityreasonsDTDisprohibitedinthisXMLdocument.ToenableDTDprocessingsettheProhibitDtdpropertyonXmlReaderSettingstofalseandpassthesettingsintoXmlReader.Createmethod."作为引用,异常发生在以下代码的第二行:using(XmlReaderreader=XmlReader.Create(uri)){reader.MoveToContent();//herewhile(rea