gpt4 book ai didi

c# - 使用正则表达式从字符串中提取 xml

转载 作者:行者123 更新时间:2023-11-30 22:15:24 26 4
gpt4 key购买 nike

我有来自服务器的以下日志文​​件,我想从以下字符串中提取 xml。

2:00:11 PM >>Response: <?xml version="1.0" encoding="UTF-8"?>

<HotelML xmlns="http://www.xpegs.com/v2001Q3/HotelML"><Head><Route Destination="TR" Source="00"><Operation Action="Create" App="UltraDirect-d1c1_" AppVer="V1_1" DataPath="/HotelML" StartTime="2013-07-31T08:33:13.223+00:00" Success="true" TotalProcessTime="711"/></Route>............

</HotelML>


3:00:11 PM >>Response: <?xml version="1.0" encoding="UTF-8"?>

<HotelML xmlns="http://www.xpegs.com/v2001Q3/HotelML"><Head><Route Destination="TR" Source="00"><Operation Action="Create" App="UltraDirect-d1c1_" AppVer="V1_1" DataPath="/HotelML" StartTime="2013-07-31T08:33:13.223+00:00" Success="true" TotalProcessTime="711"/></Route>............

</HotelML>

5:00:11 PM >>Response: <?xml version="1.0" encoding="UTF-8"?>

<HotelML xmlns="http://www.xpegs.com/v2001Q3/HotelML"><Head><Route Destination="TR" Source="00"><Operation Action="Create" App="UltraDirect-d1c1_" AppVer="V1_1" DataPath="/HotelML" StartTime="2013-07-31T08:33:13.223+00:00" Success="true" TotalProcessTime="711"/></Route>............

</HotelML>

我已经编写了相同的正则表达式,但它只匹配字符串中的第一个条目。但我想将所有 xml 字符串作为集合返回。

(?<= Response:).*>.*</.*?>

最佳答案

你为什么不匹配 <HotelML</HotelML

类似于:

<HotelML .*</HotelML>

或者,逐行遍历文件,只要找到匹配的行

^.* PM >>Response:.*$

将以下行作为 xml 读取,直到下一个匹配行...

关于c# - 使用正则表达式从字符串中提取 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17969408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com