我想使用 NSRegularExpression 从 xml 获取标签之间的数据
这是xml
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="@link" xmlns:xsi="@link" xsi:schemaLocation="@link" version="1.0">
<field left="493" top="670" right="1550" bottom="760" type="text">
<value encoding="utf-16">JENNIFER mml</value>
<line left="493" top="670" right="1550" bottom="733">
<char left="493" top="670" right="549" bottom="733" confidence="69">J</char>
<char left="565" top="670" right="605" bottom="718" confidence="71" suspicious="true">E</char>
<char left="623" top="670" right="660" bottom="718" confidence="76">N</char>
<char left="678" top="670" right="720" bottom="722" confidence="56">N</char>
<char left="736" top="674" right="776" bottom="730" confidence="80">I</char>
<char left="804" top="674" right="841" bottom="729" confidence="74">F</char>
<char left="858" top="670" right="902" bottom="725" confidence="80">E</char>
<char left="922" top="670" right="964" bottom="730" confidence="86">R</char>
<char left="965" top="670" right="1442" bottom="730" confidence="100" />
<char left="1443" top="685" right="1495" bottom="720" confidence="2" suspicious="true">m</char>
<char left="1492" top="685" right="1534" bottom="719" confidence="11" suspicious="true">m</char>
<char left="1544" top="685" right="1550" bottom="718" confidence="100" suspicious="true">l</char>
</line>
</field>
</document>
我想在值标签之间提取这些数据
<value encoding="utf-16">JENNIFER mml</value>
这是ios代码
NSString *xml =@"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><document xmlns=\"@link\" xmlns:xsi=\"@link\" xsi:schemaLocation=\"@link\" version=\"1.0\"><field left=\"493\" top=\"670\" right=\"1550\" bottom=\"760\" type=\"text\"><value encoding=\"utf-16\">JENNIFER mml</value><line left=\"493\" top=\"670\" right=\"1550\" bottom=\"733\"><char left=\"493\" top=\"670\" right=\"549\" bottom=\"733\" confidence=\"69\">J</char><char left=\"565\" top=\"670\" right=\"605\" bottom=\"718\" confidence=\"71\" suspicious=\"true\">E</char><char left=\"623\" top=\"670\" right=\"660\" bottom=\"718\" confidence=\"76\">N</char><char left=\"678\" top=\"670\" right=\"720\" bottom=\"722\" confidence=\"56\">N</char><char left=\"736\" top=\"674\" right=\"776\" bottom=\"730\" confidence=\"80\">I</char><char left=\"804\" top=\"674\" right=\"841\" bottom=\"729\" confidence=\"74\">F</char><char left=\"858\" top=\"670\" right=\"902\" bottom=\"725\" confidence=\"80\">E</char><char left=\"922\" top=\"670\" right=\"964\" bottom=\"730\" confidence=\"86\">R</char><char left=\"965\" top=\"670\" right=\"1442\" bottom=\"730\" confidence=\"100\"> </char><char left=\"1443\" top=\"685\" right=\"1495\" bottom=\"720\" confidence=\"2\" suspicious=\"true\">m</char><char left=\"1492\" top=\"685\" right=\"1534\" bottom=\"719\" confidence=\"11\" suspicious=\"true\">m</char><char left=\"1544\" top=\"685\" right=\"1550\" bottom=\"718\" confidence=\"100\" suspicious=\"true\">l</char></line></field></document>";
NSString *pattern = @"<value>(\\d+)</value>";
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:nil];
NSTextCheckingResult *textCheckingResult = [regex firstMatchInString:xml options:0 range:NSMakeRange(0, xml.length)];
NSRange matchRange = [textCheckingResult rangeAtIndex:1];
NSString *match = [xml substringWithRange:matchRange];
NSLog(@"Found string '%@'", match);