按指定规则验证xml文件。 [英] Validate xml file by specified rules.

查看:77
本文介绍了按指定规则验证xml文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是公司的新工作者,我有一个带有md文件的文件夹。

i需要制作像xml这样的文件,并按规则验证xml文件,无需xsd。

要更清楚

i需要选择文件并且代码需要读取schemaFile并将xml文件解析并输出到textBox报告中。

i需要在shema等中检查层次结构元素....

谢谢!



我尝试过:



I am a new worker in a company ,i have a folder with md files.
i need to make a file like xml,and validate the xml file by the rules,witout xsd .
to be more clear
i need to choose the file and the code need to read the "schemaFile" and to chek the xml file and output into textBox the report.
i need to check the hierarchy elements to be like in the shema etc....
thanks!

What I have tried:

public SchemaElement(XElement e)
        {
            //Need to be more.......
            if (e.Attribute("Name").Value.Equals(""))
                throw new Exception("Element "+e.Attribute("Name")+" has no 'Name' attribute. " + Environment.NewLine);
             
            Name = e.Attribute("Name").Value;
            Mandatory = e.Attribute("Mandatory") != null && e.Attribute("Mandatory").Value == "True";
            Children = e.Elements("Element").Select<xelement,>(el => new SchemaElement(el));

        }
        

        public string Name { get; set; }
        public bool Mandatory { get; set; }
        public IEnumerable<schemaelement> Children { get; set; }

        // here we need to do the chek betweem the metafile(element) and the schemafile(attribute)
        public string Validate(XElement e)
        {
            string errorDetails = string.Empty;
            if (Name != e.Name)
            {
                errorDetails += "The " + e.Name.LocalName + " is not  compatible with the schema file" + Environment.NewLine;
            }
        
            

            return errorDetails;
        }

推荐答案

我建​​议你阅读:如何:使用XSD验证(LINQ to XML) [ ^ ]
I'd suggest to read this: How to: Validate Using XSD (LINQ to XML)[^]


这篇关于按指定规则验证xml文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆