OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

wsrp-interop message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: RE: [wsrp-interop] Empty value for XMLNS


I recalled the problem with XMLNS=”” in .NET.  The problem has to do when use a QName for an attribute value.

 

Take the following XML:

 

<?xml version="1.0" encoding="IBM437"?>

   <b1:ComplexType QName="LocalName"  xmlns:b1="urn:Namespace" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <b1:Int>10</b1:Int>

    <b1:String>A description</b1:String>

</b1:ComplexType>

 

What should the namespace for the QName attribute *value* be?  .NET reports “” for the namespace when I de-serialize the above XML to a .NET class instance.  However, when I take the same class instance and serialize it, it produces the following XML:

 

<?xml version="1.0" encoding="IBM437"?>

<ComplexType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" QName="LocalName" xmlns="urn:Namespace">

   <Int>10</Int>

   <String>A description</String>

</ComplexType>

 

When this XML is de-serialized for the same class, the namespace for the QName value is “urn:Namespace”.  I’m assuming this is a bug in .NET given that de-serializing, serializing and then de-serializing once more is producing different results.  I have not found a way to force .NET to emit XMLNS=”” for a QName attribute value specifying an “” namespace value.   It would be interesting to see what Java does. 

 

I’m not totally sure of all of the interop ramifications because I’m not sure how Java serializes the above XML and the resulting namespaces.  It also depends on what the W3C XML namespace rules are for QName attribute values  which I need to look into further. 

 

Here is the code in C# I used for those interested in trying the same thing in Java:

 

[XmlRoot(Namespace="urn:Namespace")]

public class ComplexType

{

                public  int Int = 10;

                public string String = "String Value";

                [XmlAttribute]

                public XmlQualifiedName QName = new XmlQualifiedName("LocalName", "");

}

 

class Program

{

                static void Main(string[] args)

                {

                                //Build XML and emit to console

                                System.Text.StringBuilder sb1 = new StringBuilder();

                                sb1.AppendLine("<?xml version=\"1.0\" encoding=\"IBM437\"?>");

                                sb1.AppendLine("<b1:ComplexType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" QName=\"LocalName\" xmlns:b1=\"urn:Namespace\" xmlns=\"\">");

                                sb1.AppendLine("    <b1:Int>10</b1:Int>");

                                sb1.AppendLine("    <b1:String>A description</b1:String>");

                                sb1.AppendLine("</b1:ComplexType>");

                                Console.WriteLine(sb1.ToString());

                                               

                                //Deserialize and output QName value namespace

                                XmlSerializer serializer = new XmlSerializer(typeof(ComplexType));

                                ComplexType complexInstance = serializer.Deserialize(new StringReader(sb1.ToString())) as ComplexType;

                                Console.WriteLine();

                                Console.WriteLine("QName namespace = [" + complexInstance.QName.Namespace + "]");  //results in “”

 

                                //Serialize  to string buffer and emit to console

                                System.Text.StringBuilder sb2 = new StringBuilder();

                                System.IO.StringWriter writer = new StringWriter(sb2);

                                serializer.Serialize(writer, complexInstance);

                                Console.WriteLine();

                                Console.WriteLine();

                                serializer.Serialize(Console.Out, complexInstance);

 

                                //Deserialize and output QName value namespace once more

                                complexInstance = serializer.Deserialize(new StringReader(sb2.ToString())) as ComplexType;

                                Console.WriteLine();

                                Console.WriteLine();

                                Console.WriteLine("QName namespace = [" + complexInstance.QName.Namespace + "]");  //results in “urn:Namespace”

 

                                string s = Console.ReadLine();

                }

}

 

Nader

From: Nader Oteifa [mailto:nader2@netunitysoftware.com]
Sent: Thursday, December 03, 2009 12:55 PM
To: wsrp-interop@lists.oasis-open.org
Subject: [wsrp-interop] Empty value for XMLNS

 

It appears that there is not a issue with specifying an empty value for the XMLNS in .NET for XML serialization in the latest version of .NET.  However, it may have been an issue with prior versions so I will do some more digging.

 

Nader

 

 

 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]