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