Serialization across 'like' attribute names

Discussion in 'ASP .Net Web Services' started by MattL, Dec 8, 2004.

  1. MattL

    MattL Guest

    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, Dec 8, 2004
    #1
    1. Advertising

  2. MattL

    MattL Guest

    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, Dec 8, 2004
    #2
    1. Advertising

  3. 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
    http://www.geniant.com

    > 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, Dec 10, 2004
    #3
  4. MattL

    Dan Rogers Guest

    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=?=" <>
    >References: <>
    >Subject: RE: Serialization across 'like' attribute names
    >Date: Wed, 8 Dec 2004 14:41:03 -0800
    >Lines: 26
    >Message-ID: <>
    >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
    >
    >"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, Dec 10, 2004
    #4
  5. MattL

    MattL Guest

    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=?=" <>
    > >References: <>
    > >Subject: RE: Serialization across 'like' attribute names
    > >Date: Wed, 8 Dec 2004 14:41:03 -0800
    > >Lines: 26
    > >Message-ID: <>
    > >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
    > >
    > >"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, Dec 17, 2004
    #5
  6. MattL

    Dan Rogers Guest

    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=?=" <>
    >References: <>

    <>
    <>
    >Subject: RE: Serialization across 'like' attribute names
    >Date: Fri, 17 Dec 2004 08:37:15 -0800
    >Lines: 112
    >Message-ID: <>
    >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;}
    > }
    >}
    >
    >"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=?=" <>
    >> >References: <>
    >> >Subject: RE: Serialization across 'like' attribute names
    >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    >> >Lines: 26
    >> >Message-ID: <>
    >> >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
    >> >
    >> >"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, Dec 20, 2004
    #6
  7. MattL

    MattL Guest

    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=?=" <>
    > >References: <>

    > <>
    > <>
    > >Subject: RE: Serialization across 'like' attribute names
    > >Date: Fri, 17 Dec 2004 08:37:15 -0800
    > >Lines: 112
    > >Message-ID: <>
    > >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;}
    > > }
    > >}
    > >
    > >"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=?=" <>
    > >> >References: <>
    > >> >Subject: RE: Serialization across 'like' attribute names
    > >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    > >> >Lines: 26
    > >> >Message-ID: <>
    > >> >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
    > >> >
    > >> >"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, Dec 24, 2004
    #7
  8. MattL

    Dan Rogers Guest

    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=?=" <>
    >References: <>

    <>
    <>
    <>
    <>
    >Subject: RE: Serialization across 'like' attribute names
    >Date: Fri, 24 Dec 2004 07:03:05 -0800
    >Lines: 210
    >Message-ID: <>
    >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:27381
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
    >
    >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=?=" <>
    >> >References: <>

    >> <>
    >> <>
    >> >Subject: RE: Serialization across 'like' attribute names
    >> >Date: Fri, 17 Dec 2004 08:37:15 -0800
    >> >Lines: 112
    >> >Message-ID: <>
    >> >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;}
    >> > }
    >> >}
    >> >
    >> >"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=?=" <>
    >> >> >References: <>
    >> >> >Subject: RE: Serialization across 'like' attribute names
    >> >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    >> >> >Lines: 26
    >> >> >Message-ID: <>
    >> >> >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
    >> >> >
    >> >> >"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, Jan 4, 2005
    #8
  9. MattL

    MattL Guest

    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] http://www.w3.org/TR/REC-xml-names/#defaulting
    [2] http://www.w3.org/TR/REC-xml-names/#uniqAttrs

    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=?=" <>
    > >References: <>

    > <>
    > <>
    > <>
    > <>
    > >Subject: RE: Serialization across 'like' attribute names
    > >Date: Fri, 24 Dec 2004 07:03:05 -0800
    > >Lines: 210
    > >Message-ID: <>
    > >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:27381
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
    > >
    > >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=?=" <>
    > >> >References: <>
    > >> <>
    > >> <>
    > >> >Subject: RE: Serialization across 'like' attribute names
    > >> >Date: Fri, 17 Dec 2004 08:37:15 -0800
    > >> >Lines: 112
    > >> >Message-ID: <>
    > >> >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;}
    > >> > }
    > >> >}
    > >> >
    > >> >"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=?=" <>
    > >> >> >References: <>
    > >> >> >Subject: RE: Serialization across 'like' attribute names
    > >> >> >Date: Wed, 8 Dec 2004 14:41:03 -0800
    > >> >> >Lines: 26
    > >> >> >Message-ID: <>
    > >> >> >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
    > >> >> >
    > >> >> >"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, Jan 6, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,293
    deadsea
    Jan 2, 2005
  2. Carl
    Replies:
    0
    Views:
    536
  3. Replies:
    3
    Views:
    1,070
  4. Dimitri Ognibene
    Replies:
    4
    Views:
    813
    Dimitri Ognibene
    Sep 2, 2006
  5. Ramunas Urbonas
    Replies:
    1
    Views:
    422
    Dino Chiesa [Microsoft]
    Jul 27, 2004
Loading...

Share This Page