xml-serialization

Whats better: Deserialise to Object vs Just Xpathing against an XML Doc?

I've been doing alot of XML processing in C# of late and after coming back to C# from a long stint javascript coding I'm really missing some of the nice short cuts of JS. I've go a sizable XML document made up of lot so elements, child elements, etc. Representing Accommodations/Flights/Attraction tickets for an online booking. So far I...

.NET: Is There an Interface for Implemented by all XML Serialized objects?

I want a method to return an XML Serialized Typed object. Is there an interface I can use to enforce this requirement? ...

DOMImplementationLS serialize to String in UTF-8 in Java

Hi, reading the documentation for java org.w3c.dom.ls it seems as a Element only can be serialized to a String with the java native string encoding, UTF-16. I need however to create a UTF-8 string, escaped or what not, I understand that it still will be a UTF-16 String. Anyone has an idea to get around this? I need the string to pass in ...

How can I make XmlSerializer.Deserialize more strict?

I have some very similar XML structures which are in fact quite distinct, but it appears that XmlSerializer.Deserialize is very "forgiving" and will go out of its way to take XML and deserialize out into a strongly typed object I created from the source XSDs. Is there any way to make it more strict or do some type of deeper validation? ...

testing xml site?

I am trying to send and receive XML from a website using ASP.NET C# application. I tried both httpwebrequest and webclient, and both of them throw exception: "Unable to connect to the remote server. No connection could be made because the target machine actively refused it" followed by the IP Address I think. Now, is there a site o...

C# Advanced XML Serializer that doesn't require domain object pollution

Are there any closed or open source projects for a XML serializer for C# that can serialize for the most part any object without the need to pollute my domain objects with tons of attributes? That will also handle serialization of collections built with the internal generics classes? A bonus would be that it can handle serializing an int...

deserialize XML attribute with XSD

Hi all, I’m using XmlSerializer to deserialize complex object, using XSD auto-generated classes. But when it comes to enumeration, there is some problem, I want some attribute to be restricted to specific values, such as: <xs:simpleType name="choiceType"> <xs:restriction base="xs:string"> <xs:enumeration value="Yes"/> ...

Using XmlSerializer to serialize derived classes

I'm using XMLSerializer to serialize an object that contains a generic list List <ChildBase> Children {get;set} The problem is that each element derives from ChildBase which in fact is an abstract class. When I try to deserialize, I get an invalidOperationException Is there a way I can use XMLSerializer with derived objects? Thanks. ...

How to Use XmlSerializer to Serialize Collections of Objects

Here are the steps I've taken so far to work with an XmlDocument being returned by a 3rd party DLL. I saved the XmlDocument as SegmentationSummary.xml. I used XSD.exe to create SegmentationSummary.xsd. I used XSD.exe to create SegmentationSummary.cs. Here is a sample of SegmentationSummary.cs. Note that ShmResult is the root node ...

xmlserializer required/mandatory attribute/fields validation

Is there an easy way to force the WebService .Net XmlSerialiser to check that an attribute is present? In the following example, I want the webService's caller do not forget to set the Price and the Currency: public class Quote { public decimal Price; public string Currency; } [WebService] public class MyWebService : WebService ...

XmlSerializer not populating sub-elements

I've used XSD.EXE to convert an XSD into an object. That works fine and I can Deserialize using XMLSerializer just fine, except that the subelements which are generated as arrays don't populate. private SubElements[] subelementsField; /// <remarks/> [System.Xml.Serialization.XmlArrayItemAttribute("SubElement", IsNullable=f...

Forbidden characters in xml

I have an object that I am serializing to xml. It appears that a value in one of the properties contains the hex character 0x1E. I've tried setting The Encoding property of XmlWriterSettings to both "utf-16" and "unicode" but I still get an exception thrown: here was an error generating the XML document. ---> System.InvalidOperationEx...

protocol buffers .net (protobuf-net) 10x slower that xml serializer. how come?

the title says it all. i noticed that serialization as well des deserialization takes 10x as lang with protobuf-net compared to XmlSerializer. the output files however are much smaller. i find this confusing because protobuf is such a simple format that should run very fast. any hints on how to speed it are greatly appreciated. Edit: h...

XmlReader square brackets causing reader to go to errored state

I have an XmlReader that is trying to read text into a list of elements. I am having trouble getting it to reader the text: "a [ z ]". If I try with the text "a [ z ] " (same but with two trailing spaces) it works fine. Below is an example: TextReader tr = new StringReader("a [ z ]"); XmlReaderSettings settings = new XmlReaderSettings ...

RoR - Rendering nested errors on XML

Good afternoon, I'm trying to render as XML the complete ActiveRecord error list, problem is when you do something like: respond_to do |format| format.xml { render :xml => @object } end It does not render nested attributes if you don't say so, so either: you should create a template or calling explicity to_xml method and using ":i...

Modify data while serializing

I've got the hierarchial structure of files and folders inside of my application. Application works with absolute paths, which are stored in FileNode.Items list of strings. When i've got to save my project, I serialize FileNode class in XML. But, I need to convert absolute paths to relatives (if possible) and then serialize. So, my que...

Using xml to load objects. Which is the best approach?

TinyXML I have a XML file that keeps a bunch of data that is loaded into objects. Right now, I have one giant method that parses the XML file and creates the appropriate objects depending on the contents of the XML file. This function is very large and imports lots of class definitions. Would it be better to each class type to do its ...

Replace anyType node from List<Object> xml serialization

Hi, so I'm serializing an object that contains a List<Object> property, and it serializes it like this: <Explorer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <Name>Explorer1</Name> <Items> <anyType xsi:type="FolderObject"> <Name>Folder1</Name> <Items> ...

xmlserializer validation

Hi, I'm using XmlSerializer to deserialize Xml achives. But I found the class xsd.exe generated only offers capability to read the xml, but no validation. For example, if one node is missing in a document, the attribute field of the generated class will be null, rather than throws a validation exception as I expected. How can I achieve...

.NET XML Serialization and inheritance

I have structure like this: public interface A { public void method(); } public class B : A { } public class C : A { } List<A> list; List contains objects of type B and C they also have some fields that I would like to keep, can I now serialize it, deserialize back and get the proper object instances? Preferably to XML EDIT: ...