Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 序列中的XML架构上下文类型_C#_Xml_Visual Studio_Xsd_Schema - Fatal编程技术网

C# 序列中的XML架构上下文类型

C# 序列中的XML架构上下文类型,c#,xml,visual-studio,xsd,schema,C#,Xml,Visual Studio,Xsd,Schema,我正在使用C#创建一个XML模式,但我发现了一个我以前从未使用过的相当奇怪的标记序列。我希望它看起来像这样: <xsd:complexType name="Sensor_Info"> <xsd:sequence> <xsd:element name="Sensor" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:at

我正在使用C#创建一个XML模式,但我发现了一个我以前从未使用过的相当奇怪的标记序列。我希望它看起来像这样:

<xsd:complexType name="Sensor_Info">
<xsd:sequence>
    <xsd:element name="Sensor" minOccurs="1" maxOccurs="unbounded">
        <xsd:complexType>   
            <xsd:attribute name="id" type="xsd:string"/>
            <xsd:attribute name="name" type="xsd:string"/>
            <xsd:attribute name="type" type="xsd:string"/>
            <xsd:attribute name="location_id" type="xsd:string"/>
            <xsd:attribute name="unit" type="xsd:string"/>
            <xsd:attribute name="min_value" type="xsd:int"/>
            <xsd:attribute name="max_value" type="xsd:int"/>
        </xsd:complexType>
    </xsd:element>
</xsd:sequence>
<xsd:attribute name="count" type="xsd:int"/>


如果您能帮助我,我将不胜感激:)

您最好的朋友是MSDN。。。我在下面展示了一个来自文档页面的改编样本;基本上,以与XSD结构相同的方式链接SOMAPI调用

using System;
using System.Xml;
using System.Xml.Schema;

class XMLSchemaExamples
{
    public static void Main()
    {

        XmlSchema schema = new XmlSchema();

        var ct = new XmlSchemaComplexType {Name = "Sensor_Info"};
        schema.Items.Add(ct);

        var at = new XmlSchemaAttribute
        {
            Name = "count",
            SchemaTypeName = new XmlQualifiedName("int", XmlSchema.Namespace)
        };
        ct.Attributes.Add(at);

        var seq = new XmlSchemaSequence();
        ct.Particle = seq;

        var sensor = new XmlSchemaElement {Name = "Sensor", MaxOccursString = "unbounded"};
        seq.Items.Add(sensor);
        var sensorType = new XmlSchemaComplexType();
        sensor.SchemaType = sensorType;

        at = new XmlSchemaAttribute
        {
            Name = "id",
            SchemaTypeName = new XmlQualifiedName("string", XmlSchema.Namespace)
        };
        sensorType.Attributes.Add(at);
        // TODO add more attributes here

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += ValidationCallbackOne;
        schemaSet.Add(schema);
        schemaSet.Compile();

        var nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
        schema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)
    {
        Console.WriteLine(args.Message);
    }
}

你的问题是什么?我正在使用C#创建这个模式,我不知道如何在上面的序列中包含复杂类型当你说你正在使用C#创建模式时,你到底是什么意思?你的击球难度是多少?