Serialization across 'like' attribute names

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default Serialization across 'like' attribute names

    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



    MattL Guest

  2. Similar Questions and Discussions

    1. #39635 [NEW]: Better control for serialization (keyword for permit property serialization)
      From: t dot prochazka at centrum dot cz Operating system: all PHP version: 5CVS-2006-11-26 (CVS) PHP Bug Type: Feature/Change...
    2. Help getting attribute names from xml
      Can anyone help me figure out how to retrieve the attribute names from an xmlNode type variable? I have an xmlNode (student). student has 3...
    3. Retrieving XML attribute using XML::XPath::Node::Attribute
      Hi I am trying to retrieve an attribute of a particular node from my XML using "XML::XPath::Node::Attribute", but couldn't come across on how to...
    4. XML attribute for serialization
      Hi, I use XML in a webservice that looks like this: <address> <addressline>aaaa</addressline> <addressline>aaaa</addressline> <zip></zip>...
    5. avoiding XML serialization, different WSDL generation, soap serialization
      Hello, I think my problem is interesting for most of developers who wish to exchange actual business entities with webservices, not just xml...
  3. #2

    Default RE: Serialization across 'like' attribute names

    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

    "MattL" wrote:
    > 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
    >
    >
    >
    MattL Guest

  4. #3

    Default RE: Serialization across 'like' attribute names

    Hello MattL,

    That is the default behaviour. If you done specify the namespace it resolves
    to the default namespace.. am I missing something?
    HTH
    Regards,
    Dilip Krishnan
    MCAD, MCSD.net
    dkrishnan at geniant dot com
    [url]http://www.geniant.com[/url]
    > 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
    >
    > "MattL" wrote:
    >
    >> 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
    >>

    Dilip Krishnan Guest

  5. #4

    Default RE: Serialization across 'like' attribute names

    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=?=" <MattL@discussions.microsoft.com>
    >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    >Subject: RE: Serialization across 'like' attribute names
    >Date: Wed, 8 Dec 2004 14:41:03 -0800
    >Lines: 26
    >Message-ID: <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    >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.webservic es
    >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.webservic es:27099
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >
    >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
    >
    >"MattL" wrote:
    >
    >> 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
    >>
    >>
    >>
    >
    Dan Rogers Guest

  6. #5

    Default RE: Serialization across 'like' attribute names

    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;}
    }
    }

    "Dan Rogers" wrote:
    > 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=?=" <MattL@discussions.microsoft.com>
    > >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    > >Subject: RE: Serialization across 'like' attribute names
    > >Date: Wed, 8 Dec 2004 14:41:03 -0800
    > >Lines: 26
    > >Message-ID: <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    > >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.webservic es
    > >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.webservic es:27099
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    > >
    > >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
    > >
    > >"MattL" wrote:
    > >
    > >> 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
    > >>
    > >>
    > >>
    > >
    >
    >
    MattL Guest

  7. #6

    Default RE: Serialization across 'like' attribute names

    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=?=" <MattL@discussions.microsoft.com>
    >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    <qBBWJZu3EHA.768@cpmsftngxa10.phx.gbl>
    >Subject: RE: Serialization across 'like' attribute names
    >Date: Fri, 17 Dec 2004 08:37:15 -0800
    >Lines: 112
    >Message-ID: <4A75118D-53D3-463B-A15A-AA694E6CFB93@microsoft.com>
    >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.webservic es
    >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.webservic es:27278
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >
    >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;}
    > }
    >}
    >
    >"Dan Rogers" wrote:
    >
    >> 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=?=" <MattL@discussions.microsoft.com>
    >> >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    >> >Subject: RE: Serialization across 'like' attribute names
    >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    >> >Lines: 26
    >> >Message-ID: <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    >> >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.webservic es
    >> >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.webservic es:27099
    >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >> >
    >> >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
    >> >
    >> >"MattL" wrote:
    >> >
    >> >> 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
    >> >>
    >> >>
    >> >>
    >> >
    >>
    >>
    >
    Dan Rogers Guest

  8. #7

    Default RE: Serialization across 'like' attribute names

    Dan,

    I apoligize, I should have been using [XmlAttribute] and not [XmlElement]

    consider this XML

    <x:root xmlns:x="urn:A">
    <x:child Id="1" x:Id="2"/>
    </x:root>

    Now...two Ids exist. One is qualified as {""}Id and the other {urn:A}Id
    The default namespace is xmlns="" not "urn:A". When you attempt to
    serialize this you get a namespace collision in that the serializer believes
    that {""}Id and {urn:A}Id belong to the same namespace, i.e., urn:A.

    Sorry for the confusion.

    -MattL






    "Dan Rogers" wrote:
    > 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=?=" <MattL@discussions.microsoft.com>
    > >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    > <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    > <qBBWJZu3EHA.768@cpmsftngxa10.phx.gbl>
    > >Subject: RE: Serialization across 'like' attribute names
    > >Date: Fri, 17 Dec 2004 08:37:15 -0800
    > >Lines: 112
    > >Message-ID: <4A75118D-53D3-463B-A15A-AA694E6CFB93@microsoft.com>
    > >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.webservic es
    > >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.webservic es:27278
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    > >
    > >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;}
    > > }
    > >}
    > >
    > >"Dan Rogers" wrote:
    > >
    > >> 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=?=" <MattL@discussions.microsoft.com>
    > >> >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    > >> >Subject: RE: Serialization across 'like' attribute names
    > >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    > >> >Lines: 26
    > >> >Message-ID: <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    > >> >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.webservic es
    > >> >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.webservic es:27099
    > >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    > >> >
    > >> >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
    > >> >
    > >> >"MattL" wrote:
    > >> >
    > >> >> 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
    > >> >>
    > >> >>
    > >> >>
    > >> >
    > >>
    > >>
    > >
    >
    >
    MattL Guest

  9. #8

    Default RE: Serialization across 'like' attribute names

    Hi Matt,

    Yes, you're going to have lots of serialization issues if you try to do
    this. Since the nill namespace is not addressible, and because the rules
    of XML say that unqualified child attributes default to the namespace of
    their parent element, it's at least debatable as to whether this particular
    construct can even be described using a schema.

    As a "did you try this" - I'd be shocked if it worked - but did you try
    treating the nill namespace value "" as a string, and making it a qualified
    attribute?

    Dan
    --------------------
    >Thread-Topic: Serialization across 'like' attribute names
    >thread-index: AcTpyavCWD0KjUIjS4ith40Ppl1D9A==
    >X-WBNR-Posting-Host: 208.223.183.28
    >From: "=?Utf-8?B?TWF0dEw=?=" <MattL@discussions.microsoft.com>
    >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    <qBBWJZu3EHA.768@cpmsftngxa10.phx.gbl>
    <4A75118D-53D3-463B-A15A-AA694E6CFB93@microsoft.com>
    <NuQqO3u5EHA.3440@cpmsftngxa10.phx.gbl>
    >Subject: RE: Serialization across 'like' attribute names
    >Date: Fri, 24 Dec 2004 07:03:05 -0800
    >Lines: 210
    >Message-ID: <789F6E5B-745C-4B45-BDA7-B4ACFA4CEFE8@microsoft.com>
    >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.webservic es
    >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.webservic es:27381
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >
    >Dan,
    >
    >I apoligize, I should have been using [XmlAttribute] and not [XmlElement]
    >
    >consider this XML
    >
    ><x:root xmlns:x="urn:A">
    > <x:child Id="1" x:Id="2"/>
    ></x:root>
    >
    >Now...two Ids exist. One is qualified as {""}Id and the other {urn:A}Id
    >The default namespace is xmlns="" not "urn:A". When you attempt to
    >serialize this you get a namespace collision in that the serializer
    believes
    >that {""}Id and {urn:A}Id belong to the same namespace, i.e., urn:A.
    >
    >Sorry for the confusion.
    >
    >-MattL
    >
    >
    >
    >
    >
    >
    >"Dan Rogers" wrote:
    >
    >> 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=?=" <MattL@discussions.microsoft.com>
    >> >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    >> <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    >> <qBBWJZu3EHA.768@cpmsftngxa10.phx.gbl>
    >> >Subject: RE: Serialization across 'like' attribute names
    >> >Date: Fri, 17 Dec 2004 08:37:15 -0800
    >> >Lines: 112
    >> >Message-ID: <4A75118D-53D3-463B-A15A-AA694E6CFB93@microsoft.com>
    >> >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.webservic es
    >> >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.webservic es:27278
    >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >> >
    >> >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;}
    >> > }
    >> >}
    >> >
    >> >"Dan Rogers" wrote:
    >> >
    >> >> 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=?=" <MattL@discussions.microsoft.com>
    >> >> >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    >> >> >Subject: RE: Serialization across 'like' attribute names
    >> >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    >> >> >Lines: 26
    >> >> >Message-ID: <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    >> >> >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.webservic es
    >> >> >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.webservic es:27099
    >> >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    >> >> >
    >> >> >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
    >> >> >
    >> >> >"MattL" wrote:
    >> >> >
    >> >> >> 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
    >> >> >>
    >> >> >>
    >> >> >>
    >> >> >
    >> >>
    >> >>
    >> >
    >>
    >>
    >
    Dan Rogers Guest

  10. #9

    Default RE: Serialization across 'like' attribute names

    Hi Dan,
    [1] and [2] (I think) state that the unprefixed attribute *does not* inherit
    the namespace of the parent element rather it inherits the default namespace
    which is empty string. I believe that [2] also states that the {""}Id and
    {"someUri"}Id are unique since they are uniquely qualified.

    So, either I'm mistaken in my interpretation of this or the serializer
    simply cannot perform this operation (which I think indicates a bug).

    [1] [url]http://www.w3.org/TR/REC-xml-names/#defaulting[/url]
    [2] [url]http://www.w3.org/TR/REC-xml-names/#uniqAttrs[/url]

    Thoughts?

    Thx,

    -MattL


    "Dan Rogers" wrote:
    > Hi Matt,
    >
    > Yes, you're going to have lots of serialization issues if you try to do
    > this. Since the nill namespace is not addressible, and because the rules
    > of XML say that unqualified child attributes default to the namespace of
    > their parent element, it's at least debatable as to whether this particular
    > construct can even be described using a schema.
    >
    > As a "did you try this" - I'd be shocked if it worked - but did you try
    > treating the nill namespace value "" as a string, and making it a qualified
    > attribute?
    >
    > Dan
    > --------------------
    > >Thread-Topic: Serialization across 'like' attribute names
    > >thread-index: AcTpyavCWD0KjUIjS4ith40Ppl1D9A==
    > >X-WBNR-Posting-Host: 208.223.183.28
    > >From: "=?Utf-8?B?TWF0dEw=?=" <MattL@discussions.microsoft.com>
    > >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    > <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    > <qBBWJZu3EHA.768@cpmsftngxa10.phx.gbl>
    > <4A75118D-53D3-463B-A15A-AA694E6CFB93@microsoft.com>
    > <NuQqO3u5EHA.3440@cpmsftngxa10.phx.gbl>
    > >Subject: RE: Serialization across 'like' attribute names
    > >Date: Fri, 24 Dec 2004 07:03:05 -0800
    > >Lines: 210
    > >Message-ID: <789F6E5B-745C-4B45-BDA7-B4ACFA4CEFE8@microsoft.com>
    > >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.webservic es
    > >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.webservic es:27381
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    > >
    > >Dan,
    > >
    > >I apoligize, I should have been using [XmlAttribute] and not [XmlElement]
    > >
    > >consider this XML
    > >
    > ><x:root xmlns:x="urn:A">
    > > <x:child Id="1" x:Id="2"/>
    > ></x:root>
    > >
    > >Now...two Ids exist. One is qualified as {""}Id and the other {urn:A}Id
    > >The default namespace is xmlns="" not "urn:A". When you attempt to
    > >serialize this you get a namespace collision in that the serializer
    > believes
    > >that {""}Id and {urn:A}Id belong to the same namespace, i.e., urn:A.
    > >
    > >Sorry for the confusion.
    > >
    > >-MattL
    > >
    > >
    > >
    > >
    > >
    > >
    > >"Dan Rogers" wrote:
    > >
    > >> 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=?=" <MattL@discussions.microsoft.com>
    > >> >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    > >> <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    > >> <qBBWJZu3EHA.768@cpmsftngxa10.phx.gbl>
    > >> >Subject: RE: Serialization across 'like' attribute names
    > >> >Date: Fri, 17 Dec 2004 08:37:15 -0800
    > >> >Lines: 112
    > >> >Message-ID: <4A75118D-53D3-463B-A15A-AA694E6CFB93@microsoft.com>
    > >> >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.webservic es
    > >> >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.webservic es:27278
    > >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    > >> >
    > >> >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;}
    > >> > }
    > >> >}
    > >> >
    > >> >"Dan Rogers" wrote:
    > >> >
    > >> >> 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=?=" <MattL@discussions.microsoft.com>
    > >> >> >References: <8D601524-5160-4866-A47D-3A30E98F17BA@microsoft.com>
    > >> >> >Subject: RE: Serialization across 'like' attribute names
    > >> >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    > >> >> >Lines: 26
    > >> >> >Message-ID: <2C8103C2-858C-4D28-BFFE-05A84E7EDEA7@microsoft.com>
    > >> >> >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.webservic es
    > >> >> >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.webservic es:27099
    > >> >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    > >> >> >
    > >> >> >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
    > >> >> >
    > >> >> >"MattL" wrote:
    > >> >> >
    > >> >> >> 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
    > >> >> >>
    > >> >> >>
    > >> >> >>
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >>
    > >>
    > >
    >
    >
    MattL Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139