XSLT Transform XML with Namespaces

You need to provide a namespace prefix in your xslt for the elements you are transforming. For some reason (at least in a Java JAXP parser) you can’t simply declare a default namespace. This worked for me: <xsl:stylesheet version=”1.0″ xmlns:t=”http://www.test.com/” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xslFormatting=”urn:xslFormatting”> <xsl:output method=”html” indent=”no”/> <xsl:template match=”/t:ArrayOfBrokerage”> <xsl:for-each select=”t:Brokerage”> Test </xsl:for-each> </xsl:template> </xsl:stylesheet> This … Read more

Is there a way to make DataContractSerializer output cleaner XML?

This is happening because you must have marked your types (e.g. AgentNotification) with [Serializable]. When DataContractSerializer encounters a type marked with [Serializable] but no explicit [DataContract], it generates a default contract for the type that matches how BinaryFormatter serializes a class, which is to serialize all member variables of a class — even variables marked … Read more

Using DataContractSerializer to serialize, but can’t deserialize back

Here is how I’ve always done it: public static string Serialize(object obj) { using(MemoryStream memoryStream = new MemoryStream()) using(StreamReader reader = new StreamReader(memoryStream)) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); serializer.WriteObject(memoryStream, obj); memoryStream.Position = 0; return reader.ReadToEnd(); } } public static object Deserialize(string xml, Type toType) { using(Stream stream = new MemoryStream()) { byte[] data = … Read more

WCF Error “Maximum number of items that can be serialized or deserialized in an object graph is ‘65536’”

Configuring the below values solved the problem for me. Client Config: <system.serviceModel> <bindings> <basicHttpBinding> <binding name=”BasicHttpBinding_IManagementService” closeTimeout=”00:01:00″ openTimeout=”00:01:00″ receiveTimeout=”00:10:00″ sendTimeout=”00:01:00″ allowCookies=”false” bypassProxyOnLocal=”false” hostNameComparisonMode=”StrongWildcard” maxBufferSize=”2147483647″ maxBufferPoolSize=”524288″ maxReceivedMessageSize=”2147483647″ messageEncoding=”Text” textEncoding=”utf-8″ transferMode=”Buffered” useDefaultWebProxy=”true”> <readerQuotas maxDepth=”128″ maxStringContentLength=”2147483647″ maxArrayLength=”16384″ maxBytesPerRead=”4096″ maxNameTableCharCount=”16384″ /> <security mode=”None”> <transport clientCredentialType=”None” proxyCredentialType=”None” realm=”” /> <message clientCredentialType=”UserName” algorithmSuite=”Default” /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address=”http://XXXX/ManagementService.svc” … Read more

“Type not expected”, using DataContractSerializer – but it’s just a simple class, no funny stuff?

The exception that is being reported is for VDB_Sync.Model.Konstant. This means that somewhere further up the chain, this class is being pulled into another class and that class is the one being serialized. The issue is that depending on how Konstant is embedded in this class (for example, if it is in a collection or … Read more

DataContractSerializer doesn’t call my constructor?

DataContractSerializer (like BinaryFormatter) doesn’t use any constructor. It creates the object as empty memory. For example: Type type = typeof(Customer); object obj = System.Runtime.Serialization. FormatterServices.GetUninitializedObject(type); The assumption is that the deserialization process (or callbacks if necessary) will fully initialize it.