469,356 Members | 1,884 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Avoiding XML serialization namespace substitution?

AP
Hi,

I have a class that I wish to serialize to XML, part of which looks like
this:
public class TitleNotification {
[XmlAttributeAttribute(Namespace="xsi",
AttributeName="noNameSpaceSchemaLocation")]
public string NoNameSpaceSchemaLocation =
http://www.pdr.com\nhttps://extw3c.p...ification.xsd;
....
}

When the class is serialized, the relevant resulting XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<TitleNotification xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
d1p1:noNameSpaceSchemaLocation="http://www.pdr.com&#xA;https://extw3c.pdr.co
m/prism/b2b/schemas/TitleNotification.xsd" ParagonID="1234" Version="1"
Source="5" SupplierID="PA-1234" xmlns:d1p1="xsi" ...

How can I get it to generate xsi:noNameSpaceSchemaLocation instead of doing
the d1p1 substitution thing it's doing now?

Thanks,

Adam
Nov 12 '05 #1
4 11753
"AP" <ad***@indra.com> wrote in message news:OA**************@TK2MSFTNGP12.phx.gbl...
I have a class that I wish to serialize to XML, part of which looks like
this:

public class TitleNotification {
[XmlAttributeAttribute(Namespace="xsi",
AttributeName="noNameSpaceSchemaLocation")]
The Namespace property represents a namespace URI -- not a prefix.

[XmlAttribute( Namespace="http://www.w3.org/2001/XMLSchema-instance",
AttributeName="noNamespaceSchemaLocation")]

Also observe that the QName, xsi:noNamespaceSchemaLocation, is
case-sensitive.

: : How can I get it to generate xsi:noNameSpaceSchemaLocation instead of doing
the d1p1 substitution thing it's doing now?


Try using the namespace URI, XmlSerializer may re-use the xsi prefix.
If it doesn't, then it's choice of prefix is arbitrary. Correct implementations
that honor xsi:noNamespaceSchemaLocation are actually looking for:

{http://www.w3.org/2001/XMLSchema-instance,noNamespaceSchemaLocation}

Therefore, it doesn't matter what prefix it's given.

Ordinarily, you would use a public field of type XmlSerializerNamespaces,
and mark it with the [XmlNamespaceDeclarations] attribute. You could
initialize this field by Add'ing prefix and namespaceURI pairings into it.

However, the XML Schema namespace declarations are emitted by the
XmlSerializer prior to consulting the XmlNamespaceDeclarations field,
so you cannot count on your xsi namespace declaration appearing early
enough in the root element (it'll be there, though, because XmlSerializer
needs the XMLSchema-instance namespace itself.)
Derek Harmon
Nov 12 '05 #2
AP
So in other words there's no gauranteed way of doing it?

"Derek Harmon" <lo*******@msn.com> wrote in message
news:eQ*************@TK2MSFTNGP11.phx.gbl...
"AP" <ad***@indra.com> wrote in message news:OA**************@TK2MSFTNGP12.phx.gbl...
I have a class that I wish to serialize to XML, part of which looks like
this:

public class TitleNotification {
[XmlAttributeAttribute(Namespace="xsi",
AttributeName="noNameSpaceSchemaLocation")]


The Namespace property represents a namespace URI -- not a prefix.

[XmlAttribute( Namespace="http://www.w3.org/2001/XMLSchema-instance",
AttributeName="noNamespaceSchemaLocation")]

Also observe that the QName, xsi:noNamespaceSchemaLocation, is
case-sensitive.

: :
How can I get it to generate xsi:noNameSpaceSchemaLocation instead of doing the d1p1 substitution thing it's doing now?


Try using the namespace URI, XmlSerializer may re-use the xsi prefix.
If it doesn't, then it's choice of prefix is arbitrary. Correct

implementations that honor xsi:noNamespaceSchemaLocation are actually looking for:

{http://www.w3.org/2001/XMLSchema-instance,noNamespaceSchemaLocation}

Therefore, it doesn't matter what prefix it's given.

Ordinarily, you would use a public field of type XmlSerializerNamespaces,
and mark it with the [XmlNamespaceDeclarations] attribute. You could
initialize this field by Add'ing prefix and namespaceURI pairings into it.

However, the XML Schema namespace declarations are emitted by the
XmlSerializer prior to consulting the XmlNamespaceDeclarations field,
so you cannot count on your xsi namespace declaration appearing early
enough in the root element (it'll be there, though, because XmlSerializer
needs the XMLSchema-instance namespace itself.)
Derek Harmon

Nov 12 '05 #3
You can get rid of the xsd and xsi namespace declarations by using the
technique explained here:
http://weblogs.asp.net/cazzu/archive.../23/62141.aspx, at the very
beginning of the post.

HTH
--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com
"Derek Harmon" <lo*******@msn.com> wrote in message
news:eQ*************@TK2MSFTNGP11.phx.gbl...
"AP" <ad***@indra.com> wrote in message news:OA**************@TK2MSFTNGP12.phx.gbl...
I have a class that I wish to serialize to XML, part of which looks like
this:

public class TitleNotification {
[XmlAttributeAttribute(Namespace="xsi",
AttributeName="noNameSpaceSchemaLocation")]


The Namespace property represents a namespace URI -- not a prefix.

[XmlAttribute( Namespace="http://www.w3.org/2001/XMLSchema-instance",
AttributeName="noNamespaceSchemaLocation")]

Also observe that the QName, xsi:noNamespaceSchemaLocation, is
case-sensitive.

: :
How can I get it to generate xsi:noNameSpaceSchemaLocation instead of doing the d1p1 substitution thing it's doing now?


Try using the namespace URI, XmlSerializer may re-use the xsi prefix.
If it doesn't, then it's choice of prefix is arbitrary. Correct

implementations that honor xsi:noNamespaceSchemaLocation are actually looking for:

{http://www.w3.org/2001/XMLSchema-instance,noNamespaceSchemaLocation}

Therefore, it doesn't matter what prefix it's given.

Ordinarily, you would use a public field of type XmlSerializerNamespaces,
and mark it with the [XmlNamespaceDeclarations] attribute. You could
initialize this field by Add'ing prefix and namespaceURI pairings into it.

However, the XML Schema namespace declarations are emitted by the
XmlSerializer prior to consulting the XmlNamespaceDeclarations field,
so you cannot count on your xsi namespace declaration appearing early
enough in the root element (it'll be there, though, because XmlSerializer
needs the XMLSchema-instance namespace itself.)
Derek Harmon

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.665 / Virus Database: 428 - Release Date: 23/04/2004
Nov 12 '05 #4
Well, not quite what you wanted anyway :S

--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com
"Daniel Cazzulino [MVP XML]" <kz***@NOaspnet2SPAMPLZ.com> wrote in message
news:#3**************@TK2MSFTNGP10.phx.gbl...
You can get rid of the xsd and xsi namespace declarations by using the
technique explained here:
http://weblogs.asp.net/cazzu/archive.../23/62141.aspx, at the very
beginning of the post.

HTH
--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com
"Derek Harmon" <lo*******@msn.com> wrote in message
news:eQ*************@TK2MSFTNGP11.phx.gbl...
"AP" <ad***@indra.com> wrote in message

news:OA**************@TK2MSFTNGP12.phx.gbl...
I have a class that I wish to serialize to XML, part of which looks like this:

public class TitleNotification {
[XmlAttributeAttribute(Namespace="xsi",
AttributeName="noNameSpaceSchemaLocation")]


The Namespace property represents a namespace URI -- not a prefix.

[XmlAttribute( Namespace="http://www.w3.org/2001/XMLSchema-instance",
AttributeName="noNamespaceSchemaLocation")]

Also observe that the QName, xsi:noNamespaceSchemaLocation, is
case-sensitive.

: :
How can I get it to generate xsi:noNameSpaceSchemaLocation instead of doing the d1p1 substitution thing it's doing now?


Try using the namespace URI, XmlSerializer may re-use the xsi prefix.
If it doesn't, then it's choice of prefix is arbitrary. Correct

implementations
that honor xsi:noNamespaceSchemaLocation are actually looking for:

{http://www.w3.org/2001/XMLSchema-instance,noNamespaceSchemaLocation}
Therefore, it doesn't matter what prefix it's given.

Ordinarily, you would use a public field of type XmlSerializerNamespaces, and mark it with the [XmlNamespaceDeclarations] attribute. You could
initialize this field by Add'ing prefix and namespaceURI pairings into it.
However, the XML Schema namespace declarations are emitted by the
XmlSerializer prior to consulting the XmlNamespaceDeclarations field,
so you cannot count on your xsi namespace declaration appearing early
enough in the root element (it'll be there, though, because XmlSerializer needs the XMLSchema-instance namespace itself.)
Derek Harmon

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.665 / Virus Database: 428 - Release Date: 23/04/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.665 / Virus Database: 428 - Release Date: 23/04/2004
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dan Kelley | last post: by
reply views Thread by Alberto Grosso Nicolin | last post: by
reply views Thread by ktn | last post: by
1 post views Thread by andrewcw | last post: by
reply views Thread by Jeremy Chapman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.