Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
C# 用于提取html标记的正则表达式_C#_Asp.net_Regex - Fatal编程技术网

C# 用于提取html标记的正则表达式

C# 用于提取html标记的正则表达式,c#,asp.net,regex,C#,Asp.net,Regex,我需要在内容占位符中包含xml,例如: <asp:Content ID="Content2" ContentPlaceHolderID="header" runat="server"> <div> <categories> <category> <name>item 1</name> <categories&

我需要在内容占位符中包含xml,例如:

<asp:Content ID="Content2" ContentPlaceHolderID="header" runat="server">
    <div>
        <categories>
            <category>
                <name>item 1</name>
                <categories>
                    <category>
                        <name>item 1.1.</name>
                    </category>
                    <category>
                        <name>item 1.2.</name>
                    </category>
                </categories>
            </category>
        </categories>
    </div>
</asp:Content>

项目1
项目1.1。
项目1.2。
等等。我将在根类别上使用LINQ to XML构建适当的html,但是我无法使用正则表达式提取所有XML。是否有更好的方法提取xml?

请参阅和

如果包围了.xml,这有关系吗?只要把根给Linq,然后用你的方式完成它。简单、健壮且易于维护

参见和


如果包围了.xml,这有关系吗?只要把根给Linq,然后用你的方式完成它。简单、健壮且易于维护

以下正则表达式与xml匹配。它还捕获asp:content标签中的所有内容,并将其放在组1中

(?s)<asp:Content ID="[^"]*"\W+ContentPlaceHolderID="[^"]*"\W+runat="[^"]*">(.*?)</asp:Content>

(?s以下正则表达式与xml匹配。它还捕获asp:content标签中的所有内容,并将其放在组1中

(?s)<asp:Content ID="[^"]*"\W+ContentPlaceHolderID="[^"]*"\W+runat="[^"]*">(.*?)</asp:Content>

(?s)不要为此使用正则表达式,它不起作用。使用真正的XML解析器。我需要提取所有给出根元素的XML树。但重要的是要记住,xml将被html包围。不要为此使用正则表达式,它不起作用。使用真正的XML解析器。我需要提取所有给出根元素的XML树。但重要的是要记住,xml将被html包围。
Capture number: 0
Capture Me!

Capture number: 1
<div> <categories> <category> <name>item 1</name> <categories> <category> <name>item   1.1.</name> </category> <category> <name>item 1.2.</name> </category> </categories> </category> </categories> </div>