472,122 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

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 11932
"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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.