Microsoft KB Archive/815108: Difference between revisions
(importing KB archive) |
m (Text replacement - "<" to "<") |
||
Line 93: | Line 93: | ||
<li>Select '''General''' under '''Categories''', select '''XML Schema''' under '''Templates''', and then click '''Open'''. By default, XMLSchema1 is created.</li> | <li>Select '''General''' under '''Categories''', select '''XML Schema''' under '''Templates''', and then click '''Open'''. By default, XMLSchema1 is created.</li> | ||
<li><p>On the '''XML''' tab, replace the existing code with the following code:</p> | <li><p>On the '''XML''' tab, replace the existing code with the following code:</p> | ||
<pre class="codesample"> | <pre class="codesample"><?xml version="1.0" encoding="utf-8" ?> | ||
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" | |||
xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" | xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema"> | xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:element name="Root"> | |||
<xs:complexType mixed="true"> | |||
<xs:sequence> | |||
<xs:any minOccurs="0" /> | |||
<xs:element name="MyElement" type="xs:string" /> | |||
</xs:sequence> | |||
<xs:anyAttribute /> | |||
</xs:complexType> | |||
</xs:element> | |||
</xs:schema></pre></li> | |||
<li>On the '''File''' menu, click '''Save FileName As'''.</li> | <li>On the '''File''' menu, click '''Save FileName As'''.</li> | ||
<li>Type <span class="kbd userinput"> C:\MyXmlSchema.xsd</span> as the '''File name''', and then click '''Save'''.</li> | <li>Type <span class="kbd userinput"> C:\MyXmlSchema.xsd</span> as the '''File name''', and then click '''Save'''.</li> | ||
Line 122: | Line 122: | ||
'''Visual Basic .NET'''</p> | '''Visual Basic .NET'''</p> | ||
<pre class="codesample">'------------------------------------------------------------------------------ | <pre class="codesample">'------------------------------------------------------------------------------ | ||
' | ' <autogenerated> | ||
' This code was generated by a tool. | ' This code was generated by a tool. | ||
' Runtime Version: 1.0.3705.0 | ' Runtime Version: 1.0.3705.0 | ||
Line 128: | Line 128: | ||
' Changes to this file may cause incorrect behavior and will be lost if | ' Changes to this file may cause incorrect behavior and will be lost if | ||
' the code is regenerated. | ' the code is regenerated. | ||
' | ' </autogenerated> | ||
'------------------------------------------------------------------------------ | '------------------------------------------------------------------------------ | ||
Line 140: | Line 140: | ||
' | ' | ||
' | '<remarks/> | ||
<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/XMLSchema.xsd"), _ | |||
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://tempuri.org/XMLSchema.xsd", IsNullable:=false)> _ | System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://tempuri.org/XMLSchema.xsd", IsNullable:=false)> _ | ||
Public Class Root | Public Class Root | ||
' | '<remarks/> | ||
<System.Xml.Serialization.XmlTextAttribute(), _ | |||
System.Xml.Serialization.XmlAnyElementAttribute()> _ | System.Xml.Serialization.XmlAnyElementAttribute()> _ | ||
Public Any() As System.Xml.XmlNode | Public Any() As System.Xml.XmlNode | ||
' | '<remarks/> | ||
Public MyElement As String | Public MyElement As String | ||
' | '<remarks/> | ||
<System.Xml.Serialization.XmlAnyAttributeAttribute()> _ | |||
Public AnyAttr() As System.Xml.XmlAttribute | Public AnyAttr() As System.Xml.XmlAttribute | ||
End Class</pre> | End Class</pre> | ||
<p>'''Visual C# .NET'''</p> | <p>'''Visual C# .NET'''</p> | ||
<pre class="codesample">//------------------------------------------------------------------------------ | <pre class="codesample">//------------------------------------------------------------------------------ | ||
// | // <autogenerated> | ||
// This code was generated by a tool. | // This code was generated by a tool. | ||
// Runtime Version: 1.0.3705.0 | // Runtime Version: 1.0.3705.0 | ||
Line 165: | Line 165: | ||
// Changes to this file may cause incorrect behavior and will be lost if | // Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | // the code is regenerated. | ||
// | // </autogenerated> | ||
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||
Line 174: | Line 174: | ||
/// | /// <remarks/> | ||
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema.xsd")] | [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema.xsd")] | ||
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/XMLSchema.xsd", IsNullable=false)] | [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/XMLSchema.xsd", IsNullable=false)] | ||
public class Root { | public class Root { | ||
/// | /// <remarks/> | ||
[System.Xml.Serialization.XmlTextAttribute()] | [System.Xml.Serialization.XmlTextAttribute()] | ||
[System.Xml.Serialization.XmlAnyElementAttribute()] | [System.Xml.Serialization.XmlAnyElementAttribute()] | ||
public System.Xml.XmlNode[] Any; | public System.Xml.XmlNode[] Any; | ||
/// | /// <remarks/> | ||
public string MyElement; | public string MyElement; | ||
/// | /// <remarks/> | ||
[System.Xml.Serialization.XmlAnyAttributeAttribute()] | [System.Xml.Serialization.XmlAnyAttributeAttribute()] | ||
public System.Xml.XmlAttribute[] AnyAttr; | public System.Xml.XmlAttribute[] AnyAttr; |
Revision as of 09:27, 21 July 2020
Article ID: 815108
Article Last Modified on 1/11/2007
APPLIES TO
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual C# .NET 2003 Standard Edition
- Microsoft Visual C# .NET 2002 Standard Edition
SYMPTOMS
When you create an XML Schema that contains an any element without a namespace declaration, or if the value for the namespace is set to any value other than ##other and ##local along with a local element declaration, you may receive the following warnings when you generate managed classes for the schema by using the XML Schema Definition Tool (Xsd.exe):
CAUSE
The any element permits any element from the specified namespace to appear in the containing sequence or the choice element. Xsd.exe does not support the namespace for the any element and the warning messages display when you generate managed classes.
WORKAROUND
To work around this problem, do not declare local elements when you declare an any element. When you set the value for the namespace for the any element as "##other" or "##local", you may not get warnings when you generate managed classes. However, when you build a library for the generated managed class and then generate schema from the library by using XSD.exe, you may not get the namespace declaration in the generated schema.
For more information about XML Schema design patterns, visit the following MSDN Web site:
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce the Behavior
- Start Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click File.
- Select General under Categories, select XML Schema under Templates, and then click Open. By default, XMLSchema1 is created.
On the XML tab, replace the existing code with the following code:
<?xml version="1.0" encoding="utf-8" ?> <xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Root"> <xs:complexType mixed="true"> <xs:sequence> <xs:any minOccurs="0" /> <xs:element name="MyElement" type="xs:string" /> </xs:sequence> <xs:anyAttribute /> </xs:complexType> </xs:element> </xs:schema>
- On the File menu, click Save FileName As.
- Type C:\MyXmlSchema.xsd as the File name, and then click Save.
- Start Visual Studio .NET Command Prompt.
To generate the classes, type the following command at the command prompt and then press ENTER key:
In Microsoft Visual Basic .NETxsd /c /l:vb /o:C:\ C:\MyXmlSchema.xsd
In Microsoft Visual C# .NET
xsd /c /l:cs /o:C:\ C:\MyXmlSchema.xsd
You may notice the warnings that are described in the "Symptoms" section of this article.
The following managed class is generated:
Visual Basic .NET'------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated by a tool. ' Runtime Version: 1.0.3705.0 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </autogenerated> '------------------------------------------------------------------------------ Option Strict Off Option Explicit On Imports System.Xml.Serialization ' 'This source code was auto-generated by xsd, Version=1.0.3705.0. ' '<remarks/> <System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://tempuri.org/XMLSchema.xsd"), _ System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://tempuri.org/XMLSchema.xsd", IsNullable:=false)> _ Public Class Root '<remarks/> <System.Xml.Serialization.XmlTextAttribute(), _ System.Xml.Serialization.XmlAnyElementAttribute()> _ Public Any() As System.Xml.XmlNode '<remarks/> Public MyElement As String '<remarks/> <System.Xml.Serialization.XmlAnyAttributeAttribute()> _ Public AnyAttr() As System.Xml.XmlAttribute End Class
Visual C# .NET
//------------------------------------------------------------------------------ // <autogenerated> // This code was generated by a tool. // Runtime Version: 1.0.3705.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </autogenerated> //------------------------------------------------------------------------------ // // This source code was auto-generated by xsd, Version=1.0.3705.0. // using System.Xml.Serialization; /// <remarks/> [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema.xsd")] [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/XMLSchema.xsd", IsNullable=false)] public class Root { /// <remarks/> [System.Xml.Serialization.XmlTextAttribute()] [System.Xml.Serialization.XmlAnyElementAttribute()] public System.Xml.XmlNode[] Any; /// <remarks/> public string MyElement; /// <remarks/> [System.Xml.Serialization.XmlAnyAttributeAttribute()] public System.Xml.XmlAttribute[] AnyAttr; }
REFERENCES
For additional information about XML Schemas in the Microsoft .NET Framework, click the following article number to view the article in the Microsoft Knowledge Base:
313826 INFO: Roadmap for XML Schemas in the .NET Framework
Keywords: kbcodegen kbxml kbschema kbprb KB815108