【问题标题】:The value ' 'is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema'根据其数据类型“http://www.w3.org/2001/XMLSchema”,值“”无效
【发布时间】:2014-07-01 05:54:52
【问题描述】:

我是一个新手,正在学习使用 XML 编程......我创建了一个上传 xml 文件的功能......上传 xml(这是带有用户数据的简单问答数据)和验证功能抛出异常...

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

这是我的功能

  [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 很大...但是我刚刚展示了基本格式...我已经了解 ptoblem 与列 43516 abd suqestion ...

然后我需要分配什么数据类型,我需要在哪里更改数据类型??我需要在数据库表中更改吗?在 SQL 数据类型中是 int 或 bigint ...不是 short ..long ..我需要更改为 bigint 吗? 任何建议都会有帮助

【问题讨论】:

  • 此错误已解决...架构中有元素 ...显示错误...我更改更改那个“长”的错误解决了......但是另一个错误来了......“没有声明'id'属性。” ...我需要在哪里更改“id”?

标签: c# .net xml


【解决方案1】:

检查架构中定义的 id。我猜它会被定义为short,你需要把它改成int。或者,也可以使用短范围内的 id 值。

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

【讨论】:

    【解决方案2】:

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

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

    当我根据上面列出的 URL 查看 XMLSxhema 时,我发现 True | False 区分大小写。我用所有小写 true | 替换了那些警告位置布尔值。错误的。警告都消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-16
      • 2013-06-10
      • 2014-05-30
      • 1970-01-01
      相关资源
      最近更新 更多