EDN Admin
Well-known member
I have a schema setup like below. I have created a class from this schema using XSD.exe tool, then assign some values to the properties and serialize the class to XML using Xmlserializer. But the resulting XML declaration does not have the prefix to
the namespace. In this case itâs âdpâ why? <br/>
Also, I would like to know does the namespace always has to be a website? Meaning does it always has to start with
http://www.domain.com/ http://www.domain.com/ . I s the namespace used correct (Northwind.Customer.Schema)???
<pre lang="x-xml Here is the XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:dp="Northwind.Customer.Schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="Northwind.Customer.Schema"
elementFormDefault="qualified"
attributeFormDefault="unqualified
<xs:include schemaLocation="BaseSchema.xsd"/>
<xs:element name="AppealRoot
<xs:complexType>
<xs:sequence>
<xs:element name="AppealForm
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>[/code]
<br/>
<pre lang="x-c# Here is the class generated from XSD.exe tool
namespace Northwind.Customer.Schema {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="Northwind.Customer.Schema")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="Northwind.Customer.Schema", IsNullable=false)]
public partial class AppealRoot {
private AppealRootAppealForm appealFormField;
/// <remarks/>
public AppealRootAppealForm AppealForm {
get {
return this.appealFormField;
}
set {
this.appealFormField = value;
}
}
}
[/code]
<br/>
<pre lang="x-xml Here is the XML generated after serialization using XmlSeializer
<?xml version="1.0" encoding="utf-8"?>
<AppealRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="Northwind.Customer.Schema
<AppealForm>
</AppealForm>
</AppealRoot>
[/code]
View the full article
the namespace. In this case itâs âdpâ why? <br/>
Also, I would like to know does the namespace always has to be a website? Meaning does it always has to start with
http://www.domain.com/ http://www.domain.com/ . I s the namespace used correct (Northwind.Customer.Schema)???
<pre lang="x-xml Here is the XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:dp="Northwind.Customer.Schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="Northwind.Customer.Schema"
elementFormDefault="qualified"
attributeFormDefault="unqualified
<xs:include schemaLocation="BaseSchema.xsd"/>
<xs:element name="AppealRoot
<xs:complexType>
<xs:sequence>
<xs:element name="AppealForm
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>[/code]
<br/>
<pre lang="x-c# Here is the class generated from XSD.exe tool
namespace Northwind.Customer.Schema {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="Northwind.Customer.Schema")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="Northwind.Customer.Schema", IsNullable=false)]
public partial class AppealRoot {
private AppealRootAppealForm appealFormField;
/// <remarks/>
public AppealRootAppealForm AppealForm {
get {
return this.appealFormField;
}
set {
this.appealFormField = value;
}
}
}
[/code]
<br/>
<pre lang="x-xml Here is the XML generated after serialization using XmlSeializer
<?xml version="1.0" encoding="utf-8"?>
<AppealRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="Northwind.Customer.Schema
<AppealForm>
</AppealForm>
</AppealRoot>
[/code]
View the full article