值'根据其数据类型'http://www.w3.org/2001/XMLSchema', 

本文关键字:org w3 2001 www XMLSchema http 数据类型 | 更新日期: 2023-09-27 18:10:58

我是一个新来的,学习用XML编程......我创建了一个上传xml文件的函数…在上传xml(这是简单的问题和回答数据与用户数据)和验证函数抛出一个异常…

e。Message = " 'id'元素无效-值'43516'无效。根据其数据类型无效'http://www.w3.org/2001/XMLSchema:short' -字符串'43516'不是有效的Int16值。"

this is my function

  [WebMethod]
            public static bool CheckFile(string filename)
            {
                    surgeProtection = true;
                    bool returnval = false;
                    String xsdPath = "";
                    //Read the path to upload on the web server
                    string Uploadpath = ConfigurationManager.AppSettings["UploadPath"];
                    xsdPath = Uploadpath + "''" + "survey.xsd";
                    ////Validate the uploaded files on the web server
                    XmlSchemaSet schemas = new XmlSchemaSet(); //intialize schema class
                    using (FileStream schemastream = File.OpenRead(xsdPath)) //xsd file load
                    {
                        schemas.Add(XmlSchema.Read(schemastream, new ValidationEventHandler(OnValidate)));
                            //create event for schema
                    }
                    schemas.Compile();
                    String xmlPath = filename;
                    xmlPath = Uploadpath + "''" + filename;

                    XmlDocument doc = new XmlDocument();
                     byte[] mybyte = Dashboard.Model.Surveys.SurveyService.GetImageFromDB(filename);
                    string xml = Encoding.UTF8.GetString(mybyte);
                    doc.LoadXml(xml);

                    doc.Schemas = schemas; // take schema
                    doc.Validate(OnValidate); // validate schema
                    returnval = surgeProtection;
                    return returnval;
                }

This is my validation Function
        public static void OnValidate(object sender, ValidationEventArgs e)
            {
         switch (e.Severity)
            {
                case XmlSeverityType.Error:
                    surgeProtection = false;
                    sw.WriteLine("Error: " + e.Message);
            }
            }
this is my xml
    <?xml version="1.0" encoding="utf-8"?>
    <survey>
        <title>xxxxxxxxxx</title>
        <questions>
            <question>
                <description>TestDescription</description>
                <type>grid</type>
                <id>43516</id>
                <options>
                    <option value="0">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                </options>
                <sub-question description="-" id="43516_01">
                    <response>
                        <answer user="xxxx@xxx.com">7</answer>
                    </response>
                </sub-question>
            </question>
        ..and so on questions
        </questions>
        <users>
            <user iRecipientId="" sEmail="xxxx" city="xx" country="xx" responseDate="xxx"/>
        ..and so on
        </users>
    </survey>

这是我的表设计在DB

ID          int         Unchecked
ImageName   varchar(200)    Unchecked
Image   varbinary(MAX)  Unchecked

XML非常大…但我只是展示了基本格式…我知道问题出在43516栏,

我需要分配什么数据类型,我需要在哪里更改数据类型?我需要在DB表处换车吗?在SQL数据类型是int或bigint…不短……长. .我需要改成bigint吗?如有任何建议,请参考

值'根据其数据类型'http://www.w3.org/2001/XMLSchema', 

检查在模式中定义了什么id。我猜它会被定义为short,你需要把它改成int。或者使用一个短范围的id值。

见http://msdn.microsoft.com/en-us/library/aa719879 (v = vs.71) . aspx

当我将Visual Studio 2005项目升级到VS2010时,我收到了这些警告。

警告1 'IsAppSettingsProperty'属性无效-值'False'根据其数据类型'http://www.w3.org/2001/XMLSchema:boolean'无效-字符串'False'不是有效的布尔值。

当我查看上面列出的URL的xmlshema时,我发现True | False是区分大小写的。我将这些警告位置布尔值全部替换为小写true | false。