Hi Matt,
I think you are saying (ignoring your implementation) that you want to get
the following XML:
<Root xmlns="urn:A">
<id>namespaced value</id>
<id xmlns="">non-namespaced value</id>
</Root>
Is this correct? From a schema perspective, this is nearly impossible to
describe, so best practice would seem to dicate not doing this. However,
since it is to a degree, just a matter of what you can serialize, I think
it's possible to make this happen.
If so, try this:
[XmlRoot("urn:A")]
public class Root
{
[XmlElement(ElementName="id", Namespace="urn:A", DataType="string")]
public string firstId;
[XmlElement(ElementName="id", Form=XmlSchemaForm.Unqualified,
DataType="string")]
public string secondId;
public Root()
{
firstId = "namespaced value";
secondId = "non-namespaced value";
}
}
Hope this helps,
Dan Rogers
Microsoft Corporation
--------------------
Thread-Topic: Serialization across 'like' attribute names
thread-index: AcTkVqqruD3zK+TeQkiNrEeE6lyK7Q==
X-WBNR-Posting-Host: 208.223.183.28
From: "=?Utf-8?B?TWF0dEw=?=" <
[email protected]>
References: <
[email protected]>
<
[email protected]>
<
[email protected]>
Subject: RE: Serialization across 'like' attribute names
Date: Fri, 17 Dec 2004 08:37:15 -0800
Lines: 112
Message-ID: <
[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:27278
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
Example
if this example the namespaces should be
{urn:A}Root
{""}Id
{urn:A}Id
[XmlRoot(Namespace="urn:A")]
[XmlType(Namespace="urn:A")]
public class Root
{
public class Root()
{
_xmlns.Add("x","urn:A");
}
private string _id;
private string _otherId;
private XmlSerializerNamespaces _xmlns = new XmlSerializerNamespaces();
[XmlNamespaceDeclarations()]
public XmlSerializerNamespaces Xmlns
{
get{return _xmlns;}
set{_xmlns = value;}
}
[XmlAttribute(Form=XmlSchemaForm.Unqualified)]
public string Id
{
get{return _id;}
set{_id = value;}
}
[XmlAttribute("Id", Namespace="urn:A", Form=XmlSchemaForm.Qualified)]
public string OtherId
{
get{return _otherId;}
set{_otherId = value;}
}
}
:
Hi Matt,
Please send me the schema you wish to make classes for.
Thanks
Dan Rogers
Microsoft Corporation
--------------------
Thread-Topic: Serialization across 'like' attribute names
thread-index: AcTddv9JsCx498jxRx2TdGUFw+iZkg==
X-WBNR-Posting-Host: 208.223.183.27
From: "=?Utf-8?B?TWF0dEw=?=" <
[email protected]>
References: <
[email protected]>
Subject: RE: Serialization across 'like' attribute names
Date: Wed, 8 Dec 2004 14:41:03 -0800
Lines: 26
Message-ID: <
[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:27099
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
To clarify myself:
The unqualified attribute SHOULD NOT inherit the default namespace and
it
appears that the serializer "puts" it in the default namespace.
-MattL
:
This serialization error appears to be not correct...
When a class defined in a specific namespace,e.g., "urn:A" and two
attributes which have the same local name, e.g., "Id", with one one
attribute
defined as Qualified and in the namespace "urn:A" and the other
attribute is
defined as Unqualified cannot be serialized.
The problem (as it appears to me) is that an unqualifed attribute
does
not
inherit a default namespace (per Namespaces in XML) and this is the
error
thrown by the serializer, i.e., that both "Id" attributes appear in
the
same
namespace.
Thoughts!
-MattL