473,232 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 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 12085
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
Hello all, Please consider this code: #ifndef FOO_INCLUDED #define FOO_INCLUDED // File: foo.h class foo {
3
by: Dan Kelley | last post by:
I have an application which sends messages to an external application. All data is submitted as a string in an Xml format specified by the other application, along with some custom elements we have...
0
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ...
0
by: ktn | last post by:
Hi all, I'm a .NET beginner and I've got a problem on a program where I try to do an XML serialization. I get the following error : "An unmanaged exception of type...
0
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
0
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem...
0
by: Jeremy Chapman | last post by:
I'm building a class with xml serialization attrbutes. Below I've included the class and the xml it serializes to. It pretty much matches what I want except for the Message property of the...
0
by: groovyghoul | last post by:
Hi I have the following XML file: =========================================================== <?xml version="1.0" encoding="UTF-16"?> <Policy xmlns="http://tempuri.org/richard.xsd"> <TransType...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.