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
使用Regexp搜索XML_Xml_Regex_Delphi - Fatal编程技术网

使用Regexp搜索XML

使用Regexp搜索XML,xml,regex,delphi,Xml,Regex,Delphi,如何通过正则表达式搜索xml文件并在Delphi中获得特定的属性值 例如,在此xml中: <?xml version=”1.0” encoding=”UTF-8” ?> <School> <Class> <StudentID> 1 </StudentID> <StudentName> Joe </StudentName> <StudentFami

如何通过正则表达式搜索xml文件并在Delphi中获得特定的属性值

例如,在此xml中:

<?xml version=”1.0” encoding=”UTF-8” ?> 
<School>
    <Class>
        <StudentID> 1 </StudentID> 
        <StudentName> Joe </StudentName> 
        <StudentFamily> Brown </StudentFamily> 
    </Class>
    <Class>
        <StudentID> 2 </StudentID> 
        <StudentName> Michel </StudentName> 
        <StudentFamily> Adams </StudentFamily> 
    </Class>
    <Class>
        <StudentID> 3 </StudentID> 
        <StudentName> Joel </StudentName> 
        <StudentFamily> Thompson </StudentFamily> 
    </Class>

</School>

1.
乔
棕色的
2.
米歇尔
亚当斯
3.
乔尔
汤普森
也就是说,搜索“Joe*”(在StudentName属性中)代码应该返回“Brown”和“Thompson”(来自StudentFamily属性)

我可以在简单的情况下为xmlDocument使用FindNode函数,但我必须使用正则表达式

欢迎提出任何意见。

那么:
(?:\Joe.*\[\s]*\s*)(\w*)
当然,您必须构建模式并将“Joe*”作为“Joe.*”放在正确的位置

尝试:

(?:<StudentName>\sjoe[^< ]*).*?\n.*?<StudentFamily>([^<]*)

(?:\sjoe[^<]*)。\n.*([^您正在编写的正则表达式有任何语言限制吗?还有,您不能仅使用xpath的原因吗?我建议您使用xpath。这将更可行。这个问题已经由bobince回答:FWIW,我没有投反对票。我的原因是“不清楚您在问什么”。停止为此任务使用正则表达式。它是错误的工具。