Connecting Tech Pros Worldwide Forums | Help | Site Map

Xsd question

Robert Strickland
Guest
 
Posts: n/a
#1: Nov 12 '05
I developed a schema that uses the following for schema settings:

elementFormDefault="qualified"
xmlns:at=http://www.mycompany.com
targetNamespace="http://www.mycompany.com"

The goal is to namespace the my elements with "at" - example is
at:myElementName.

I use xsd to build a class. I then use the class to add data and then use
the XmlSerializer to serialize the class. When I look at the Xml stream
generated from the serialization, I do not see my target name space prefixed
to the elements.

How can I serialize and get the target namespace to appear on the Xml stream
correctly?



Christoph Schittko [MVP]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Xsd question



Robert,

The best way is to pass an XmlSerializerNamespaces object to the
Serialize() method, as I describe in [0].

You could also modify the generated class to force the namespace prefix
when serializing instances [1], but I am generally not a friend of
modifying generated code
[0] http://www.topxml.com/xmlserializer/...at_runtime.asp
[1] http://www.topxml.com/xmlserializer/...namespaces.asp
[color=blue]
> -----Original Message-----
> From: Robert Strickland [mailto:bstrickland@comporium.net]
> Posted At: Tuesday, December 28, 2004 4:11 PM
> Posted To: microsoft.public.dotnet.xml
> Conversation: Xsd question
> Subject: Xsd question
>
> I developed a schema that uses the following for schema settings:
>
> elementFormDefault="qualified"
> xmlns:at=http://www.mycompany.com
> targetNamespace="http://www.mycompany.com"
>
> The goal is to namespace the my elements with "at" - example is
> at:myElementName.
>
> I use xsd to build a class. I then use the class to add data and then[/color]
use[color=blue]
> the XmlSerializer to serialize the class. When I look at the Xml[/color]
stream[color=blue]
> generated from the serialization, I do not see my target name space
> prefixed
> to the elements.
>
> How can I serialize and get the target namespace to appear on the Xml
> stream
> correctly?[/color]


Robert Strickland
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Xsd question


That worked. Thanks.

"Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in message
news:epQvmGV7EHA.1260@TK2MSFTNGP12.phx.gbl...[color=blue]
>
> Robert,
>
> The best way is to pass an XmlSerializerNamespaces object to the
> Serialize() method, as I describe in [0].
>
> You could also modify the generated class to force the namespace prefix
> when serializing instances [1], but I am generally not a friend of
> modifying generated code
> [0] http://www.topxml.com/xmlserializer/...at_runtime.asp
> [1] http://www.topxml.com/xmlserializer/...namespaces.asp
>[color=green]
>> -----Original Message-----
>> From: Robert Strickland [mailto:bstrickland@comporium.net]
>> Posted At: Tuesday, December 28, 2004 4:11 PM
>> Posted To: microsoft.public.dotnet.xml
>> Conversation: Xsd question
>> Subject: Xsd question
>>
>> I developed a schema that uses the following for schema settings:
>>
>> elementFormDefault="qualified"
>> xmlns:at=http://www.mycompany.com
>> targetNamespace="http://www.mycompany.com"
>>
>> The goal is to namespace the my elements with "at" - example is
>> at:myElementName.
>>
>> I use xsd to build a class. I then use the class to add data and then[/color]
> use[color=green]
>> the XmlSerializer to serialize the class. When I look at the Xml[/color]
> stream[color=green]
>> generated from the serialization, I do not see my target name space
>> prefixed
>> to the elements.
>>
>> How can I serialize and get the target namespace to appear on the Xml
>> stream
>> correctly?[/color]
>
>[/color]


Closed Thread