【发布时间】:2013-11-25 16:57:49
【问题描述】:
我在 SoapMessage 中的内容如下所示:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://service.xxx.dk/DialogModtag</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:382b4943-26e8-4698-a275-c3149d2d889e</MessageID>
<To xmlns="http://www.w3.org/2005/08/addressing">http://xxx.dk/12345678</To>
<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">uuid:cb2320dc-c8ab-4880-94cb-2ab68129216f</RelatesTo>
</soap:Header>
<soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-2515">
Some content ...
</soap:Body>
我正在尝试使用如下代码提取
Pattern PATTERN_SOAP_ACTION =
Pattern.compile(".*Header.*Action.*>(.*)<.*Action.*Header.*", Pattern.DOTALL);
String text = readFile("c:\\temp\\DialogUdenBilag.xml");
Matcher matcherSoapAction = PATTERN_SOAP_ACTION.matcher(text);
if (matcherSoapAction.matches()) { System.out.println(matcherSoapAction.group(1)); }
else { System.out.println("SaopAction not found"); }
这似乎适用于小型肥皂消息。但是当 soap:Body 增长到 +1MB 时,matches() 函数调用需要几分钟才能完成。
有什么想法可以让我的正则表达式模式对 CPU 更友好?
【问题讨论】: