473,394 Members | 1,703 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,394 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 18347
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Naresh Agarwal | last post by:
Hi I'm using SAX Parser of Xerces Java v2.4.0 for XML Parsing. I want to perform schema validations on the xml. The problem is that root element of XML document does not have...
1
by: John | last post by:
I have an input document that contains a large base64 encoded document. This document also declares a schema location in the root element. I want to write an XSL stylesheet that makes an exact...
1
by: Naresh Agarwal | last post by:
Hi I'm using SAX Parser of Xerces Java v2.4.0 for XML Parsing. I want to perform schema validations on the xml. The problem is that root element of XML document does not have...
0
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this attribute causes some problems. The programm is...
0
by: Ron James | last post by:
I'm developing a GUI application in C#. I have a schema file (.XSD) and am able to serialize and deserialize the applications data using the schema file to an .XML file. (I'm using xsd.exe to...
2
by: kaush | last post by:
Hi all, I am trying to serialize a C# object into a XML document using "XmlSerializer" class. One of the elements of the XML document needs a "xsi:schemaLocation" attribute. I am not sure how to...
1
by: jean | last post by:
I am creating an xmldatadocument from an acess database with visual basic. Here is the header code I am using: Dim xmldcl As XmlDeclaration = myDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes")...
0
by: kolja2003 | last post by:
Hi, I need to program the creation of the XML file of given structure. I try to do it through the serialization of class object. hence I need to write the class definition which will be serialized...
0
by: spiceworm | last post by:
Hi all, I'm getting really confused how to solve this. I've got this class generated from XSD with xsd (from visual studio 2005) namespace gpx { using System.Xml.Serialization;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.