In this class for example, I want to force a limit of characters the first/last name can allow.
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Is there a way to force the string limit restriction for the first or last name, so when the client serializes this before sending ...
Is there a clever way of adding XML serialization instructions without modifying the serialized class?
I don’t like the default serialization and I can’t modify the class. I was considering inheriting the class, and using Shadows (VB.NET) to re-implement the properties (with the serialization instructions), but it results in a lot of du...
I'm writing a small application in VB.NET and I would like some of the classes to be able to write themselves out to XML to serve as a "save" feature. I have seen XSD files used to generate VB classes that can serialize themselves into and out of XML very easily. How would I do this if I do have any pre-existing XML format that I need ...
I'm currently working on a project which needs to persist any kind of objects (of which implementation we don't have any control) so these objects could be recovered afterwards.
We can't implement a ORM because we can't restrict the users of our library at development time.
Our first alternative was to serialize it with the Java defau...
I want to be able to load a serialized xml class to a Soap Envelope. I am starting so I am not filling the innards so it appears like:
<Envelope
xmlns="http://schemas.xmlsoap.org/soap/envelope/" />
I want it to appear like:
<Envelope
xmlns="http://schemas.xmlsoap.org/soap/envelope/" ></Envelope>`
The class I wrote is t...
Is there a way for me to serialize an object in .NET without the XML Namespaces automatically serializing also? It seems that by default .NET believes the XSI and XSD namespaces should be included, but I don't want them there.
...
I am using XmlSerializer to write and read an object to xml in C#. I currently use the attributes XmlElement and XmlIgnore to manipulate the serialization of the object.
If my xml file is missing an xml element that I require, my object still deserializes (xml -> object) just fine. How do I indicate (preferably via Attributes) that a...
I'm writing code to do Xml serialization. With below function.
public static string SerializeToXml(object obj)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, obj);
return writer.ToString();
}
}
If the argumen...
Our Flex app would like to work with requests and responses as object graphs (nothing unusual there) e.g. response becomes the model of some view, and would be a structure with several layers of nesting.
** Now, ideally we would like to use the same client (and server) side objects for different message formats e.g. XML and AMF, and hav...
I have the following xml I'd like to deserialize into a class
<?xml version="1.0" encoding="utf-8" ?>
<root>
<element1>String1</element1>
<element2>String2</element2>
</root>
I am trying to serialize it into the following class:
[XmlRoot("root")]
public class root
{
[XmlElement("element1")]
internal st...
My schema specifies a namespace, but the documents don't. What's the simplest way to ignore namespace during JAXB unmarshalling (XML -> object)?
In other words, I have
<foo><bar></bar></foo>
instead of,
<foo xmlns="http://tempuri.org/"><bar></bar></foo>
...
Once a programmer decides to implement IXmlSerializable, what are the rules and best practices for implementing it? I've heard that GetSchema() should return null and ReadXml should move to the next element before returning. Are these true? And what about WriteXml: should it write a root element for the object or is it assumed that the r...
We are having a problem whenever our application makes use of the XML
Serializer, when we are logged in as a user who has a username containing
Japanese characters.
We have prepared a sample application that tests the serializer on its own:
TestClass myClass = new TestClass();
myClass.MyString = "Hello Wo...
Hi,
I have an xml that looks like this:
<Config>
<A></A>
<Template><B/><C/></Template>
</Config>
and I would like to deserialize it in to get the <Template><B/><C/></Template> bit as a XmlElement or XmlNode. But when I try like this:
public class Config
{
public string A;
public XmlElement Template;
}
the Template is set...
When serializing/de-serializing certain classes I've come across the need to flag or mark certain properties as CDATA elements (due to their content). I am currently handling this like so:
<XmlElement("MessageText")> _
Public Property XmlContentLeft() As XmlCDataSection
Get
Dim doc As New XmlDataDocument()
...
When I serialize;
public class SpeedDial
{
public string Value { get; set; }
public string TextTR { get; set; }
public string TextEN { get; set; }
public string IconId { get; set; }
}
It results:
<SpeedDial>
<Value>110</Value>
<TextTR>Yangın</TextTR>
<TextEN>Fire</TextEN>
<IconId>39</IconId>
</SpeedDia...
I have the following class
[XmlRoot(ElementName= "webSites")] //No capital w at the beginning
public class WebSites : List<WebSite>
{
}
public class WebSite
{
[XmlAttribute("name")]
public string Name { set; get; }
[XmlAttribute("url")]
public String Url { set; get; }
}
this is serialized to
<?xml version="1.0"...
I have a .NET Web app which consumes a Java-based Web service. One of the objects, named Optional, contains search criteria fields. The schema is the following:
<xsd:complexType name="Optional">
<xsd:sequence>
<xsd:element name="FromAmount" nillable="true" type="xsd:float" minOccurs="0" />
<xsd:element name="ToAmount" nillable="tr...
Hello!
I'm serializing class which contains DateTime property.
public DateTime? Delivered { get; set; }
After serializing Delivered node contains DateTime formatted like this:
2008-11-20T00:00:00
How can I change this property to make it look like this:
2008-11-20 00:00:00
Thanks in advance
...
I have the following xml that's sent to me from a web service. I'm using .NET to deserialize it, but I'm getting an exception saying that its formatted wrong. There is an error in XML document (2, 2) Now, if I understand that correctly, it's not liking that it's finding the first <error> node.
<?xml version="1.0" encoding="UTF-8"?>
<m...