ixmlserializable

Why does XmlSerializer throws an Exception and raise a ValidationEvent when a schema validation error occurs inside IXmlSerializable.ReadXml()

核能气质少年 提交于 2021-02-17 04:59:46
问题 I have written some tests for reading an XML file and validating it against an XSD schema. My data objects are using a mix of attribute based and custom IXmlSerializable implementation and I am using the XmlSerializer to perform deserialization. My test involves inserting an unknown element into the XML so that it does not conform to the schema. I then test if the validation event fires. If the unknown element is placed in the XML so it's a child of one of the attribute based data classes (i

IXmlSerializable dictionary in C# without 'Key'/'Value' nodes

北城余情 提交于 2021-01-27 23:38:31
问题 I'm trying to serialize a dictionary in C#. All the examples I've been able to find create XML like the following: <Dictionary> <ArrayOfEntries> <Entry> <Key>myFirstKey</Key> <Value>myFirstValue</Value> </Entry> <Entry> <Key>mySecondKey</Key> <Value>mySecondValue</Value> </Entry> </ArrayOfEntries> </Dictionary> It varies, sometimes the ArrayOfEntries node isn't necessary, but I still see the regular pattern of the dictionary's key-value pairs being stored in their own nodes. What I would like

Implementing IXmlSerializable Requires Collection Property to Have Setter

情到浓时终转凉″ 提交于 2020-01-11 09:46:12
问题 I have a collection property that is of a custom type which inherits from BindingList. Currently, this property gets serialized via XmlSerializer even though it has no Setter. I now am trying to implement IXmlSerializable on this custom collection class and see that the WriteXml() and ReadXml() interface methods only get called if my collection property has a Setter. Why does serialization ignore this property now unless there is a Setter when before it serialized correctly without one. To

How can I control the root element namespace and name when serializing an IXmlSerializable object with the data contract serializer?

懵懂的女人 提交于 2020-01-09 11:49:26
问题 I have a type that implements IXmlSerializable which I am serializing with DataContractSerializer. How can I control the root element namespace and name when serializing it as the root element of an XML document? Say I have the following type: public partial class PersonDTO : IXmlSerializable { public string Name { get; set; } #region IXmlSerializable Members public System.Xml.Schema.XmlSchema GetSchema() { return null; } public void ReadXml(System.Xml.XmlReader reader) { Name = reader["name"

IXmlSerializable and Root Element Prefix

為{幸葍}努か 提交于 2020-01-06 18:32:31
问题 I have looked everywhere and not a single response is valid or the question is just slightly off to the point of not getting me the answer I need. Given all the searches I have looked for there seems to be one MASSIVE flaw in .Net's implementation of xml serialization. Default: [XmlRoot("root", Namespace="http://myclass.org/")] public class MyClass { } void Main() { XmlSerializer ser = new XmlSerializer(typeof(MyClass)); XmlSerializerNamespaces xsn = new XmlSerializerNamespaces(); xsn.Add("mc

Windows 8 store app XmlWriter does not write anything to file

感情迁移 提交于 2019-12-25 03:56:06
问题 I am not very well versed with .NET's XML libraries and trying to wrap my head around IXmlSerializable interface. I am developing a windows store app (W8) and wish to use the IXmlSerializable interface, however am running into issues. XmlTextWriter is not available in windows store apps so I am using XmlWriter's factory method but my code does not output anything to the XML file (its blank). If I use XmlSerializer, the XML file is output as expected, but wish to implement IXmlSerializable

XmlSerialization of IXmlSerializable array

浪子不回头ぞ 提交于 2019-12-23 18:10:01
问题 I have a scenario where the Request objects are XML Serailized and sent back to a TCP server for getting processed. The serialization is done by a legacy framework. Needless to say, I can't make changes in the legacy framework. The legacy framework, however is smart enough to realize if a request object is implementing IXmlSerializable , in that case it takes the WriteXml method of the interface to do the serialization. I wanted to keep maximum control of the serailzation process in my hand,

Custom Serialization using XmlSerializer

梦想与她 提交于 2019-12-22 18:16:11
问题 I have a class that I need to do some custom XML output from, thus I implement the IXmlSerializable interface. However, some of the fields I want to output with the default serialization except I want to change the xml tag names. When I call serializer.Serialize, I get default tag names in the XML. Can I change these somehow? Here is my code: public class myClass: IXmlSerializable { //Some fields here that I do the custom serializing on ... // These fields I want the default serialization on

Getting the calling variable name of a parameter

末鹿安然 提交于 2019-12-22 09:06:38
问题 In relation to the question Get the name of parameters from a calling method and Finding the Variable Name passed to a Function in C# I'm still looking for a way to define the WhatDoesTheAnimalSay_WANTED method: I want to know the name of the variable that's used as a parameter: public class Farm { public readonly string Cow = "Muuuuhh"; public string Cat { get; set; } public void MainFunction() { var dog = "WauWau"; var kiwi = new Bird("QueeeekQueeek"); Cat = "Miiiaaauuuu"; // This one works

Help with implementing IXmlSerializable on this XML

断了今生、忘了曾经 提交于 2019-12-13 05:40:01
问题 Here's the XML: <?xml version="1.0" encoding="utf-8" ?> <SAPPHIRE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <TRANSACTION-CODE>NEW</TRANSACTION-CODE> <CUSTOMER-NUMBER>100398598</CUSTOMER-NUMBER> <CUSTOMER-NAME>CART DUDE</CUSTOMER-NAME> <ACCOUNT-TYPE /> <PERSON FNAME="CART" LNAME="DUDE" RESPONSIBLITY="CART DUDE" /> <SOURCE>cplestore</SOURCE> <TRAN-REFERENCE>13374470</TRAN-REFERENCE> <ORDER> <ORDER-NUMBER NUMBER="00241662693" REFERENCE=