2
голосов
5ответов
2873 просмотров

How to XML deserialize an object of Unknown Type?

I want to save my object to hard disk (like cache) with XmlSerializer. In this case, I don't have any problem. However, when I want to deserialize this XML to an object, I get an error. Is there any way to deserialize XML to an unknown object or to an object that I created?

217
голосов
12ответов
204903 просмотров

{"<user xmlns=""> was not expected.} Deserializing Twitter XML</user>

I'm pulling in the XML from Twitter via OAuth. I'm doing a request to http://twitter.com/account/verify_credentials.xml, which returns the following XML: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;user&gt; &lt;id&gt;16434938&lt;/id&gt; &lt;name&gt;Lloyd Sparkes&lt;/name&gt; &lt;screen...

1
голосов
3ответов
3081 просмотров

XML Serialization of Derived Classes

I have an array of elements that I need to serialize using XmlSerializer. The problem I'm having is I have 2 derived classes, and serializing them so they have an element name of the common base, doesn't seem to work. So, this is how the XML should look: &lt;Root&gt; &lt;Base&gt; foo &lt;/...

1
голосов
2ответов
2162 просмотров

DeSerialize DataTable Row Collection into List<t></t>

I have a DataTable with rows of data. I have a class with properties that match the row column names. How can I have a List that is populated from the DataTable Row information? Do I call something like (MyType)new XmlSerializer(typeof(MyType)).Deserialize(new XMLReader(Table.WriteXML()));

0
голосов
1ответов
2309 просмотров

c# - how do I serialize an Array&lt;&gt; to XML? (getting "You must implement a default accessor on System.Array because it inherits from ICollection.")

I'm a bit stumped here. I just really want to XML Serialize an Array&lt;&gt; but I'm getting: "You must implement a default accessor on System.Array because it inherits from ICollection." A snippet from my code is below. Any idea? Array a = Files.ToArray(); XmlSerializer serializer = ...

1
голосов
2ответов
2310 просмотров

C# Castle ActiveRecord: How to elegantly (XML) serialize ActiveRecord objects?

I'm having a difficult time finding information on how to elegantly serialize ActiveRecord objects. We would like to use XML as the format because we need to output our objects in such a way that another program will be able to feasibly parse them. XML-Serialization is usually very easy and str...

0
голосов
1ответов
451 просмотров

Need help Serializing System.Data.OracleClient.OracleCommand to XML?

Trying to write a list of oracle commands to XML but keep getting this error. This is driving me crazy. Thanks in advance. "There was an error reflecting type 'System.Data.OracleClient.OracleCommand'." Friend Sub WriteDataToFile(ByVal Commands As List(Of System.Data.OracleClient.OracleCommand...

0
голосов
2ответов
3459 просмотров

c# serialize second level element to property

I am trying to create serializable class but I want to map second level element to my property of class. What's the best way of doing this. Example xml &amp; class &lt;SearchResult&gt; &lt;Head&gt; &lt;Title q="test"&gt;My search Result&lt;/Title&gt; &lt;/Head&gt; &lt;Results&gt; &lt;Res...

2
голосов
1ответов
1910 просмотров

Why does XMLSerializer take DefaultValue Attribute of base class to serialize

using System.ComponentModel; using System.IO; using System.Xml.Serialization; namespace SerializerTest { static class Program { static void Main() { using (TextWriter textWriter = new StreamWriter("data.xml")) { Data data = new Data(); new ...

19
голосов
4ответов
7302 просмотров

XmlSerializer Performance Issue when Specifying XmlRootAttribute

I'm currently having a really weird issue and I can't seem to figure out how to resolve it. I've got a fairly complex type which I'm trying to serialize using the XmlSerializer class. This actually functions fine and the type serializes properly, but seems to take a very long time in doing so; ...

33
голосов
9ответов
34875 просмотров

How to exclude null properties when using XmlSerializer

I'm serializing a class like this public MyClass { public int? a { get; set; } public int? b { get; set; } public int? c { get; set; } } All of the types are nullable because I want minimal data stored when serializing an object of this type. However, when it is serialized with on...

1
голосов
2ответов
2332 просмотров

Help Merging XML Data

I have two XMLDocuments that contain some similar information but there are other nodes that contain different information between the two. I am using XMLSerialization to put my data into a structure as shown here I know you can merge XML files by using a DataSet as shown here but I want to som...

2
голосов
2ответов
630 просмотров

Can I use a C# collection to hold class instances with self-referential relationships?

I need to model in memory a collection web files, but that relationships between them. That is file A (e.g. html) may have a link to file B (e.g. css) and file C (e.g. javascript). Also file D may also require file B. If I wanted to delete file A I would need to make sure any files it uses ...

1
голосов
2ответов
449 просмотров

How should you implement Serialization? (interface/convention wise)

I implement an xml serialization based on Marc's answer. Should this be part of the class itself, ie Apple.Serialize/Deserialize? Although Deserialize would be static in that case, as you might not have an instance to call it on. Or should I have another class for Serialize/Deserialize? If so,...

1
голосов
1ответов
332 просмотров

Javascript library for exporting XML

I'm currently using couchdb to store documents as JSON. One of my clients needs to grab XML (for now). Anyone know any good javascript libraries that can take a javascript object (or json string) and export valid xml? Thanks!

1
голосов
1ответов
313 просмотров

User Defined XML Serialization

I have the following structure in C#: [Serializable] public struct Line { public Line(Point startPoint, Point endPoint) { StartPoint = startPoint; EndPoint = endPoint; } public Point StartPoint; public Point EndPoint; } wh...

2
голосов
2ответов
4899 просмотров

How to implement xml serialization for custom types?

I have some types that I want to serialize/deserialize and generate a UI based on the selected object. The UI will also change the object which in turn I will have to serialize to store it in my app. So: [obj_apple stored in the app] -&gt; select obj_apple -&gt; deserialize -&gt; show in UI -&g...

26
голосов
14ответов
59808 просмотров

Can I force JAXB not to convert " into ", for example, when marshalling to XML?

I have an Object that is being marshalled to XML using JAXB. One element contains a String that includes quotes ("). The resulting XML has &amp;quot; where the " existed. Even though this is normally preferred, I need my output to match a legacy system. How do I force JAXB to NOT convert the ...

6
голосов
3ответов
11340 просмотров

XML Serialization of HTML

Okay this one DID it! Thanks to all of you! public class Result { public String htmlEscaped { set; get; } [XmlIgnore] public String htmlValue { set; get; } [XmlElement("htmlValue")] public XmlCDataSection htmlValueCData { get ...

65
голосов
5ответов
52404 просмотров

Deciding on when to use XmlDocument vs XmlReader

I'm optimizing a custom object -&gt; XML serialization utility, and it's all done and working and that's not the issue. It worked by loading a file into an XmlDocument object, then recursively going through all the child nodes. I figured that perhaps using XmlReader instead of having XmlDocumen...

1
голосов
5ответов
713 просмотров

How to create a class to XML Serializer

I have the following xml format: &lt;FavouriteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;Customer&gt; &lt;ID&gt;12&lt;/ID&gt; &lt;ID&gt;2&lt;/ID&gt; &lt;ID&gt;5&lt;/ID&gt; &lt;/Customer&gt; &lt;Supplier&g...

0
голосов
1ответов
2202 просмотров

Python XML Serializers

Can some recommend an XML serializer that is element or attribute centric, and that doesn't use key-value pairs. For example, GAE db.model has a to_xml() function but it writes out like this: &lt;property name="firstname" type="string"&gt;John&lt;/property&gt; &lt;property name="lastname"...

3
голосов
3ответов
2176 просмотров

XmlMtomReader reading strategy

Consider the following code: Stream stream = GetStreamFromSomewhere(); XmlDictionaryReader mtomReader =XmlDictionaryReader.CreateMtomReader ( stream, Encoding.UTF8, XmlDictionaryReaderQuoatas.Max ); /// ... /// is there best way to read binary data from mtomReader's element?? string elemen...

16
голосов
4ответов
13261 просмотров

What is the Jaxb equivalent of a Text node value?

I am looking to convert a class that looks like this ... public class Amenity { public String id; public String value; } into the following XML using JaxB annotations: &lt;amenity id="id-string-here"&gt;value-string-here&lt;/amenity&gt; Does anyone know what annotation to use on the v...

4
голосов
2ответов
3348 просмотров

.NET XmlIgnore By Default?

Is there a way to have XmlSerializer ignore all members by default, unless I say otherwise? I have a base class and several derived classes with lots of members, but most I do not want to be serialized. Only a select few are acceptable for serialization.

1
голосов
1ответов
1487 просмотров

XmlSerializer chokes on xsi:type?

EDIT: See Pavel's answer below -- the 'type not recognized error' was caused by a mismatch between the class heirarchy in my parsing code (which I did not include here) and my XML schema. The 'type not recognized' error was something of a red herring, but once I fixed things the parsing works j...

1
голосов
2ответов
324 просмотров

Request for code review: does such XmlSerializer factory have any drawbacks?

People tend to recommend to cache XmlSerializer instances. Is this still actual? (if no, when has it become so?). Also I came up with the following code and ask to review it. Does it have any drawbacks? Will it use many threads\cores for different types? How can I improve it? The code: publ...

0
голосов
2ответов
430 просмотров

Xml Deserialization - Sequence of Mutiple Types

Given the following fragment where links is a sequence of unbounded imagelinks and documentlinks, what should the deserailized class be? &lt;Values&gt; &lt;Links&gt; &lt;ImageLink&gt;http://#&lt;/ImageLink&gt; &lt;ImageLink&gt;http://#&lt;/ImageLink&gt; &lt;DocumentLink&gt;h...

4
голосов
1ответов
540 просмотров

How to handle XML Character reference in scala?

I am trying to generate some XML on-the-fly in Scala. I want to use a numeric character reference inside the XML and write out the resultant XML to an output stream. Example: val myXml = &lt;body&gt;Hello&amp;#8198;World&lt;/body&gt; val writer = new java.io.FileWriter("test") scala.xml.XML.wr...

1
голосов
2ответов
516 просмотров

Nested Classes w/ Same Name in Separate Assemblies Causing Serialization Headaches

I’m working with a poorly-engineered API. I have a class that I need to serialize, and I have control over the makeup of the class, but not the types that make up the properties the class is serialzing. An example is below: &lt;Project&gt; &lt;SomeProperty1 /&gt; &lt;Install&gt; &lt;Defa...