Hi,

I need to be able to serialize my class such that the XML file contains a
stylesheet directive after the XML definition as below:

<?xml version="1.0" ?>
<xml-stylesheet type="test/xsl" href="abc.xsl"?>
<root>
etc
etc

Can anyone tell me how to do this please?

Pazza.

Re: Serialize a class adding a stylesheet by Kevin

Kevin
Fri Nov 11 11:14:14 CST 2005

If you serialize a class, only class members will be serialized. As an XSL
stylesheet is a string, you have the option of creating a member of the
class (which represents the stylesheet) that can be serialized with it.
Otherswise, use an external stylesheet.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Complex things are made up of
Lots of simple things.

"Pazza" <Pazza@discussions.microsoft.com> wrote in message
news:CED9C30E-5967-4F70-8B30-3E632E649F60@microsoft.com...
> Hi,
>
> I need to be able to serialize my class such that the XML file contains a
> stylesheet directive after the XML definition as below:
>
> <?xml version="1.0" ?>
> <xml-stylesheet type="test/xsl" href="abc.xsl"?>
> <root>
> etc
> etc
>
> Can anyone tell me how to do this please?
>
> Pazza.



Re: Serialize a class adding a stylesheet by Pazza

Pazza
Mon Nov 14 02:15:03 CST 2005

Kevin,

Thanks for your reply.

I created a schema and generated the class using xsd.exe.
I then created an instance of the class and serialized it out to a file.
The result was the following:

<?xml version="1.0" encoding="utf-8"?>
<className xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<stylesheet type="text/xsl" href="stylesheets/abc.xsl" />
<Header>
etc
etc

I have two problems with this ...
(1) The <stylesheet> element is not formed properly ie. it is missing the ?
from the start and end. And
(2) I want the <stylesheet> element to appear before the root elment
<className>.

Can you offer any advice on how to correct (1) and how to achive (2) please?

Pazza
"Kevin Spencer" wrote:

> If you serialize a class, only class members will be serialized. As an XSL
> stylesheet is a string, you have the option of creating a member of the
> class (which represents the stylesheet) that can be serialized with it.
> Otherswise, use an external stylesheet.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> Complex things are made up of
> Lots of simple things.
>
> "Pazza" <Pazza@discussions.microsoft.com> wrote in message
> news:CED9C30E-5967-4F70-8B30-3E632E649F60@microsoft.com...
> > Hi,
> >
> > I need to be able to serialize my class such that the XML file contains a
> > stylesheet directive after the XML definition as below:
> >
> > <?xml version="1.0" ?>
> > <xml-stylesheet type="test/xsl" href="abc.xsl"?>
> > <root>
> > etc
> > etc
> >
> > Can anyone tell me how to do this please?
> >
> > Pazza.
>
>
>

Re: Serialize a class adding a stylesheet by Pazza

Pazza
Wed Nov 16 06:51:02 CST 2005

Help!!, is there anyone out there who can help with this please.

"Pazza" wrote:

> Kevin,
>
> Thanks for your reply.
>
> I created a schema and generated the class using xsd.exe.
> I then created an instance of the class and serialized it out to a file.
> The result was the following:
>
> <?xml version="1.0" encoding="utf-8"?>
> <className xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <stylesheet type="text/xsl" href="stylesheets/abc.xsl" />
> <Header>
> etc
> etc
>
> I have two problems with this ...
> (1) The <stylesheet> element is not formed properly ie. it is missing the ?
> from the start and end. And
> (2) I want the <stylesheet> element to appear before the root elment
> <className>.
>
> Can you offer any advice on how to correct (1) and how to achive (2) please?
>
> Pazza
> "Kevin Spencer" wrote:
>
> > If you serialize a class, only class members will be serialized. As an XSL
> > stylesheet is a string, you have the option of creating a member of the
> > class (which represents the stylesheet) that can be serialized with it.
> > Otherswise, use an external stylesheet.
> >
> > --
> > HTH,
> >
> > Kevin Spencer
> > Microsoft MVP
> > ..Net Developer
> > Complex things are made up of
> > Lots of simple things.
> >
> > "Pazza" <Pazza@discussions.microsoft.com> wrote in message
> > news:CED9C30E-5967-4F70-8B30-3E632E649F60@microsoft.com...
> > > Hi,
> > >
> > > I need to be able to serialize my class such that the XML file contains a
> > > stylesheet directive after the XML definition as below:
> > >
> > > <?xml version="1.0" ?>
> > > <xml-stylesheet type="test/xsl" href="abc.xsl"?>
> > > <root>
> > > etc
> > > etc
> > >
> > > Can anyone tell me how to do this please?
> > >
> > > Pazza.
> >
> >
> >

Re: Serialize a class adding a stylesheet by Kevin

Kevin
Wed Nov 16 08:04:30 CST 2005

I can give it another shot. First, if you serialize a class, the class name
element is going to be the root element of the serialized class. Now, you
can certainly create an XML file from the class, but if you want the
stylesheet to appear before the class element, it can not be a member of the
class, but would have to be inserted into the XML file. What exactly is the
requirement you are trying to fulfill here? Because if serializing a class
is the requirement, you're barking up the wrong tree. But if creating an XML
document from a serialized class is your goal, that is certainly doable. The
XML document will not *be* the serialized class, but may *contain* the
serialized class.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Pazza" <Pazza@discussions.microsoft.com> wrote in message
news:2D8C553C-016D-4795-8A01-18406D9B45FA@microsoft.com...
> Help!!, is there anyone out there who can help with this please.
>
> "Pazza" wrote:
>
>> Kevin,
>>
>> Thanks for your reply.
>>
>> I created a schema and generated the class using xsd.exe.
>> I then created an instance of the class and serialized it out to a file.
>> The result was the following:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <className xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>> <stylesheet type="text/xsl" href="stylesheets/abc.xsl" />
>> <Header>
>> etc
>> etc
>>
>> I have two problems with this ...
>> (1) The <stylesheet> element is not formed properly ie. it is missing the
>> ?
>> from the start and end. And
>> (2) I want the <stylesheet> element to appear before the root elment
>> <className>.
>>
>> Can you offer any advice on how to correct (1) and how to achive (2)
>> please?
>>
>> Pazza
>> "Kevin Spencer" wrote:
>>
>> > If you serialize a class, only class members will be serialized. As an
>> > XSL
>> > stylesheet is a string, you have the option of creating a member of the
>> > class (which represents the stylesheet) that can be serialized with it.
>> > Otherswise, use an external stylesheet.
>> >
>> > --
>> > HTH,
>> >
>> > Kevin Spencer
>> > Microsoft MVP
>> > ..Net Developer
>> > Complex things are made up of
>> > Lots of simple things.
>> >
>> > "Pazza" <Pazza@discussions.microsoft.com> wrote in message
>> > news:CED9C30E-5967-4F70-8B30-3E632E649F60@microsoft.com...
>> > > Hi,
>> > >
>> > > I need to be able to serialize my class such that the XML file
>> > > contains a
>> > > stylesheet directive after the XML definition as below:
>> > >
>> > > <?xml version="1.0" ?>
>> > > <xml-stylesheet type="test/xsl" href="abc.xsl"?>
>> > > <root>
>> > > etc
>> > > etc
>> > >
>> > > Can anyone tell me how to do this please?
>> > >
>> > > Pazza.
>> >
>> >
>> >



Re: Serialize a class adding a stylesheet by Pazza

Pazza
Wed Nov 16 08:48:17 CST 2005

Kevin,

I want to create an XML document from my object. This XML document will then
form the input into another application and at the same time be viewable via
IE using the stylesheet.

Pazza.

"Kevin Spencer" wrote:

> I can give it another shot. First, if you serialize a class, the class name
> element is going to be the root element of the serialized class. Now, you
> can certainly create an XML file from the class, but if you want the
> stylesheet to appear before the class element, it can not be a member of the
> class, but would have to be inserted into the XML file. What exactly is the
> requirement you are trying to fulfill here? Because if serializing a class
> is the requirement, you're barking up the wrong tree. But if creating an XML
> document from a serialized class is your goal, that is certainly doable. The
> XML document will not *be* the serialized class, but may *contain* the
> serialized class.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> If you push something hard enough,
> it will fall over.
> - Fudd's First Law of Opposition
>
> "Pazza" <Pazza@discussions.microsoft.com> wrote in message
> news:2D8C553C-016D-4795-8A01-18406D9B45FA@microsoft.com...
> > Help!!, is there anyone out there who can help with this please.
> >
> > "Pazza" wrote:
> >
> >> Kevin,
> >>
> >> Thanks for your reply.
> >>
> >> I created a schema and generated the class using xsd.exe.
> >> I then created an instance of the class and serialized it out to a file.
> >> The result was the following:
> >>
> >> <?xml version="1.0" encoding="utf-8"?>
> >> <className xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> >> <stylesheet type="text/xsl" href="stylesheets/abc.xsl" />
> >> <Header>
> >> etc
> >> etc
> >>
> >> I have two problems with this ...
> >> (1) The <stylesheet> element is not formed properly ie. it is missing the
> >> ?
> >> from the start and end. And
> >> (2) I want the <stylesheet> element to appear before the root elment
> >> <className>.
> >>
> >> Can you offer any advice on how to correct (1) and how to achive (2)
> >> please?
> >>
> >> Pazza
> >> "Kevin Spencer" wrote:
> >>
> >> > If you serialize a class, only class members will be serialized. As an
> >> > XSL
> >> > stylesheet is a string, you have the option of creating a member of the
> >> > class (which represents the stylesheet) that can be serialized with it.
> >> > Otherswise, use an external stylesheet.
> >> >
> >> > --
> >> > HTH,
> >> >
> >> > Kevin Spencer
> >> > Microsoft MVP
> >> > ..Net Developer
> >> > Complex things are made up of
> >> > Lots of simple things.
> >> >
> >> > "Pazza" <Pazza@discussions.microsoft.com> wrote in message
> >> > news:CED9C30E-5967-4F70-8B30-3E632E649F60@microsoft.com...
> >> > > Hi,
> >> > >
> >> > > I need to be able to serialize my class such that the XML file
> >> > > contains a
> >> > > stylesheet directive after the XML definition as below:
> >> > >
> >> > > <?xml version="1.0" ?>
> >> > > <xml-stylesheet type="test/xsl" href="abc.xsl"?>
> >> > > <root>
> >> > > etc
> >> > > etc
> >> > >
> >> > > Can anyone tell me how to do this please?
> >> > >
> >> > > Pazza.
> >> >
> >> >
> >> >
>
>
>

Re: Serialize a class adding a stylesheet by Spidey

Spidey
Wed Nov 16 08:53:04 CST 2005

Here is how you should be able to achieve this:

Serialize your object to a string instead of serializing your object
directly to a file. You can use the Serialize(TextWriter, object)
overload of the XMLSerializer using a StringWriter as the first
parameter (StringWriter derives from TextWriter).

The StringWriter class writes its information to an underlying
StringBuilder that can be accessed by calling the GetStringBuilder()
method of the StringWriter.

Create an empty XmlDocument object and load Xml from the StringBuilder.

Use the CreateProcessingInstruction method to create your stylesheet
declaration.

Call the XmlDocument.InsertBefore method to insert your stylesheet
declaration before the root node.

Save the XmlDocument to a file.

I haven't tried this out, but I think it should work. Let me know if
you have any problems.

Regards,
Sarin.

Pazza wrote:
> Hi,
>
> I need to be able to serialize my class such that the XML file contains a
> stylesheet directive after the XML definition as below:
>
> <?xml version="1.0" ?>
> <xml-stylesheet type="test/xsl" href="abc.xsl"?>
> <root>
> etc
> etc
>
> Can anyone tell me how to do this please?
>
> Pazza.


Re: Serialize a class adding a stylesheet by Kevin

Kevin
Wed Nov 16 12:11:32 CST 2005

Yes, assuming that creating an XML document is the requirement, something
like this is what I would recommend.

Another, and perhaps more elegant solution is to serialize the class as an
XML document, and use XSLT to transform it with the additional code into an
XML document that has the additional code (style sheet, etc). This separates
the transform from the serialized class nicely, and enables you to perform
different transforms for different uses.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Spidey" <sarin.rajendran@gmail.com> wrote in message
news:1132152783.999627.319870@g49g2000cwa.googlegroups.com...
> Here is how you should be able to achieve this:
>
> Serialize your object to a string instead of serializing your object
> directly to a file. You can use the Serialize(TextWriter, object)
> overload of the XMLSerializer using a StringWriter as the first
> parameter (StringWriter derives from TextWriter).
>
> The StringWriter class writes its information to an underlying
> StringBuilder that can be accessed by calling the GetStringBuilder()
> method of the StringWriter.
>
> Create an empty XmlDocument object and load Xml from the StringBuilder.
>
> Use the CreateProcessingInstruction method to create your stylesheet
> declaration.
>
> Call the XmlDocument.InsertBefore method to insert your stylesheet
> declaration before the root node.
>
> Save the XmlDocument to a file.
>
> I haven't tried this out, but I think it should work. Let me know if
> you have any problems.
>
> Regards,
> Sarin.
>
> Pazza wrote:
>> Hi,
>>
>> I need to be able to serialize my class such that the XML file contains a
>> stylesheet directive after the XML definition as below:
>>
>> <?xml version="1.0" ?>
>> <xml-stylesheet type="test/xsl" href="abc.xsl"?>
>> <root>
>> etc
>> etc
>>
>> Can anyone tell me how to do this please?
>>
>> Pazza.
>