且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在其中一个元素未在中间关闭的情况下读取XML文件.(C#)

更新时间:2023-11-24 20:53:10

尝试使用称为substring的代码

Try Using Code called substring

string a = "code";
for(int i = 0;i < a.substring;i++)
{
    if(a.substring(i,1)=="o")
    {
        MessageBox.Show("I found a letter o");
    }
}



a.substring(i,1)
| AAAAAAAAA || |
| AAAAAAAAA || |-您想要阅读多少个字母
| AAAAAAAAA |
| AAAAAAAAA | ---应从其开始读取的位置
|
| --------------您要读取的字符串



a.substring(i,1)
|AAAAAAAAA| |
|AAAAAAAAA| |- how many letters you want to read
|AAAAAAAAA|
|AAAAAAAAA|--- position from which should reading start
|
|-------------- string you want to read


如果格式不正确,则它不是XML文件.您必须确定要查找的模式,然后将其作为字符串处理.如果树结构对您很重要,那么您将必须制定一些规则来确定未关闭的标签何时隐式关闭.

如果文件只是不完整(即,直到文件末尾是正确的,但某些标签未关闭),则可以编写一个非常简单的预解析器,计算出未关闭的标签是什么,结束标记到文件末尾,并将其提供给XML解析器.
If it''s not correctly formatted, then it''s not an XML file. You''ll have to work out what the patterns you want to look for are, and deal with it as a string. If the tree structure is important to you, then you''ll have to work out some rules for when unclosed tags get implicitly closed.

If the file is simply incomplete (i.e. it is correct up to the end of file but some tags are unclosed), you can write a very simple pre-parser that works out what the unclosed tags are, adds the closing tags to the end of the file, and gives it to an XML parser.