xml-serialization

Using XmlSerializer with an array in the root element

筅森魡賤 提交于 2019-12-28 04:01:13
问题 I have an XML document similar to the following: <scan_details> <object name="C:\Users\MyUser\Documents\Target1.doc"> ... </object> <object name="C:\Users\MyUser\Documents\Target2.doc"> ... </object> ... </scan_details> I am hoping to use the System.Xml.Serialization attributes to simplify XML deserialization. The issue I have is I cannot work out how to specify that the root node contains an array. I have tried creating the following classes: [XmlRoot("scan_details")] public class

How can I XML Serialize a DateTimeOffset Property?

人盡茶涼 提交于 2019-12-28 03:04:24
问题 The DateTimeOffset property I have in this class doesn't get rendered when the data is represented as Xml. What do I need to do to tell the Xml serialization to render that proper as a DateTime or DateTimeOffset ? [XmlRoot("playersConnected")] public class PlayersConnectedViewData { [XmlElement("playerConnected")] public PlayersConnectedItem[] playersConnected { get; set; } } [XmlRoot("playersConnected")] public class PlayersConnectedItem { public string name { get; set; } public

How to write a comment to an XML file when using the XmlSerializer?

大兔子大兔子 提交于 2019-12-28 02:44:29
问题 I have an object Foo which I serialize to an XML stream. public class Foo { // The application version, NOT the file version! public string Version {get;set;} public string Name {get;set;} } Foo foo = new Foo { Version = "1.0", Name = "Bar" }; XmlSerializer xmlSerializer = new XmlSerializer(foo.GetType()); This works fast, easy and does everything currently required. The problem I'm having is that I need to maintain a separate documentation file with some minor remarks. As in the above

What is MyAssembly.XmlSerializers.dll generated for?

你离开我真会死。 提交于 2019-12-27 19:51:50
问题 I am working on a project which generates an assembly. I just noticed that an additional assembly *.XmlSerializers.dll is being generated. Why this file is auto generated and what it is used for? 回答1: In .NET implementation, the XmlSerializer generates a temporary assembly for serializing/deserializing your classes (for performance reasons). It can either be generated on the fly (but it takes time on every execution), or it can be pregenerated during compilation and saved in this assembly you

What is MyAssembly.XmlSerializers.dll generated for?

冷暖自知 提交于 2019-12-27 19:46:59
问题 I am working on a project which generates an assembly. I just noticed that an additional assembly *.XmlSerializers.dll is being generated. Why this file is auto generated and what it is used for? 回答1: In .NET implementation, the XmlSerializer generates a temporary assembly for serializing/deserializing your classes (for performance reasons). It can either be generated on the fly (but it takes time on every execution), or it can be pregenerated during compilation and saved in this assembly you

XSLT: How to convert XML Node to String

江枫思渺然 提交于 2019-12-27 12:04:30
问题 <ROOT> <A> <B>TESTING</B> </A> </ROOT> XSL: <xsl:variable name="nodestring" select="//A"/> <xsl:value-of select="$nodestring"/> I am trying to convert XML nodeset to string using XSL. Any thoughts? 回答1: You need to serialize the nodes. The most simple for your example would be something like <xsl:template match="ROOT"> <xsl:variable name="nodestring"> <xsl:apply-templates select="//A" mode="serialize"/> </xsl:variable> <xsl:value-of select="$nodestring"/> </xsl:template> <xsl:template match="

.net XML Serialization - Storing Reference instead of Object Copy

十年热恋 提交于 2019-12-27 11:14:05
问题 In .Net/C# Application, I have data structures which have references to each other. When I serialize them, .Net Serializes all references with separate object copies. In Following Example, I am trying to serialize to Array of 'Person' A 'Person' may have reference to another person. public class Person { public string Name; public Person Friend; } Person p1 = new Person(); p1.Name = "John"; Person p2 = new Person(); p2.Name = "Mike"; p1.Friend = p2; Person[] group = new Person[] { p1, p2 };

XmlSerializer with dependencies results in Null reference exception

徘徊边缘 提交于 2019-12-25 16:42:07
问题 I'm running into an issue with Xml serialization of my own class. It is a derived class, which doesn't naturally have a parameterless constructor - I had to add one just for the sake of serialization. Of course, because of that I'm running into dependency/order issue. Here's a simplification, which I hope still illustrates the problem (I reserve the right to augment the illustration if it turns out I didn't capture the problem - I just didn't want to dump a complicated Object Model on you :))

PHP and sitemap.xml

房东的猫 提交于 2019-12-25 14:15:20
问题 I am planning to build a script that will create a sitemap.xml for my site, say, every day (cron will execute the script). Should I just build the XML string and save it as a file? Or would there be some benefit to using one of PHP's classes/functions/etc. for XML? If I should be using some sort of PHP class/function/etc., what should it be? 回答1: For simple XML it is often easier to just output the string. But the more complex your document gets, the more benefit you will get from using an

PHP and sitemap.xml

China☆狼群 提交于 2019-12-25 14:14:54
问题 I am planning to build a script that will create a sitemap.xml for my site, say, every day (cron will execute the script). Should I just build the XML string and save it as a file? Or would there be some benefit to using one of PHP's classes/functions/etc. for XML? If I should be using some sort of PHP class/function/etc., what should it be? 回答1: For simple XML it is often easier to just output the string. But the more complex your document gets, the more benefit you will get from using an