471,053 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

XmlSerializer and xsi:schemaLocation


I am trying to use XmlSerializer to serialize a class I have created
specifically for generating an XML file.
The problem is that the XML file must contain a xsi:schemaLocation
attribute in my root node but I can't figure out any way to do it.

Here is what the resulting XML file must look like (small sample):

<TXLife xmlns="http://ACORD.org/Standards/Life/2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*xsi:schemaLocation="http://ACORD.org/Standards/Life/2
TXLife2.11.01.xsd"* Version="2.11.01">
<blah>whatever</blah>
</TXLife>

The closest I can get is this:

<TXLife xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*schemaLocation="http://ACORD.org/Standards/Life/2 TXLife2.11.01.xsd"*
Version="2.11.01" xmlns="http://ACORD.org/Standards/Life/2">
<blah>whatever</blah>
</TXLife>

Here is the class definition:

using System;
using System.Xml.Serialization;
namespace nbi
{

[XmlRoot (Namespace="http://ACORD.org/Standards/Life/2")]
public class TXLife
{
[XmlElement]
public string blah = "whatever";

[XmlAttributeAttribute ("schemaLocation")]
public string xsiSchemaLocation="http://ACORD.org/Standards/Life/2
TXLife2.11.01.xsd";

[XmlAttributeAttribute]
public string Version="2.11.01";

public TXLife()
{
}
}

}

I can't change the schemaLocation attribute on the class member to
xsi:schemaLocation because I then get the following error at runtime:
THERE IS AN INVALID NAME CHARACTER IN XSI:SCHEMALOCATION.

This is in .net 1.1 by the way.

Any ideas?
--
grochmal
------------------------------------------------------------------------
grochmal's Profile: http://www.hightechtalks.com/m235
View this thread: http://www.hightechtalks.com/t407381

Sep 22 '06 #1
2 17511
Modify [XmlAttributeAttribute] Namespace property to specify the xsi
namespace:
[XmlAttributeAttribute ("schemaLocation",
Namespace="XmlSchema.InstanceNamespace")]
public string
xsiSchemaLocation="http://ACORD.org/Standards/Life/2TXLife2.11.01.xsd";

"grochmal" <gr*************@no-mx.forums.yourdomain.com.auwrote in message
news:gr*************@no-mx.forums.yourdomain.com.au...
>
I am trying to use XmlSerializer to serialize a class I have created
specifically for generating an XML file.
The problem is that the XML file must contain a xsi:schemaLocation
attribute in my root node but I can't figure out any way to do it.

Here is what the resulting XML file must look like (small sample):

<TXLife xmlns="http://ACORD.org/Standards/Life/2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*xsi:schemaLocation="http://ACORD.org/Standards/Life/2
TXLife2.11.01.xsd"* Version="2.11.01">
<blah>whatever</blah>
</TXLife>

The closest I can get is this:

<TXLife xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*schemaLocation="http://ACORD.org/Standards/Life/2 TXLife2.11.01.xsd"*
Version="2.11.01" xmlns="http://ACORD.org/Standards/Life/2">
<blah>whatever</blah>
</TXLife>

Here is the class definition:

using System;
using System.Xml.Serialization;
namespace nbi
{

[XmlRoot (Namespace="http://ACORD.org/Standards/Life/2")]
public class TXLife
{
[XmlElement]
public string blah = "whatever";

[XmlAttributeAttribute ("schemaLocation")]
public string xsiSchemaLocation="http://ACORD.org/Standards/Life/2
TXLife2.11.01.xsd";

[XmlAttributeAttribute]
public string Version="2.11.01";

public TXLife()
{
}
}

}

I can't change the schemaLocation attribute on the class member to
xsi:schemaLocation because I then get the following error at runtime:
THERE IS AN INVALID NAME CHARACTER IN XSI:SCHEMALOCATION.

This is in .net 1.1 by the way.

Any ideas?
--
grochmal
------------------------------------------------------------------------
grochmal's Profile: http://www.hightechtalks.com/m235
View this thread: http://www.hightechtalks.com/t407381

Sep 22 '06 #2
AR
Thanks, this was useful to resolve a problem I was having as well.

--
Agustin Rodriguez, MCSD
"Zafar Abbas" wrote:
Modify [XmlAttributeAttribute] Namespace property to specify the xsi
namespace:
[XmlAttributeAttribute ("schemaLocation",
Namespace="XmlSchema.InstanceNamespace")]
public string
xsiSchemaLocation="http://ACORD.org/Standards/Life/2TXLife2.11.01.xsd";

"grochmal" <gr*************@no-mx.forums.yourdomain.com.auwrote in message
news:gr*************@no-mx.forums.yourdomain.com.au...

I am trying to use XmlSerializer to serialize a class I have created
specifically for generating an XML file.
The problem is that the XML file must contain a xsi:schemaLocation
attribute in my root node but I can't figure out any way to do it.

Here is what the resulting XML file must look like (small sample):

<TXLife xmlns="http://ACORD.org/Standards/Life/2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*xsi:schemaLocation="http://ACORD.org/Standards/Life/2
TXLife2.11.01.xsd"* Version="2.11.01">
<blah>whatever</blah>
</TXLife>

The closest I can get is this:

<TXLife xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*schemaLocation="http://ACORD.org/Standards/Life/2 TXLife2.11.01.xsd"*
Version="2.11.01" xmlns="http://ACORD.org/Standards/Life/2">
<blah>whatever</blah>
</TXLife>

Here is the class definition:

using System;
using System.Xml.Serialization;
namespace nbi
{

[XmlRoot (Namespace="http://ACORD.org/Standards/Life/2")]
public class TXLife
{
[XmlElement]
public string blah = "whatever";

[XmlAttributeAttribute ("schemaLocation")]
public string xsiSchemaLocation="http://ACORD.org/Standards/Life/2
TXLife2.11.01.xsd";

[XmlAttributeAttribute]
public string Version="2.11.01";

public TXLife()
{
}
}

}

I can't change the schemaLocation attribute on the class member to
xsi:schemaLocation because I then get the following error at runtime:
THERE IS AN INVALID NAME CHARACTER IN XSI:SCHEMALOCATION.

This is in .net 1.1 by the way.

Any ideas?
--
grochmal
------------------------------------------------------------------------
grochmal's Profile: http://www.hightechtalks.com/m235
View this thread: http://www.hightechtalks.com/t407381


Nov 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sarah Tegtmeier | last post: by
reply views Thread by Ron James | last post: by
reply views Thread by kolja2003 | 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.