[英]How to read key and value from xml file using delimiters in java?
我想用java閱讀以下xml <LINE>
標簽。 你能幫忙嗎? 提前致謝。
<?xml version="1.0" encoding="UTF-8" ?>
<LINE>002:OR,004:0001,002:01,002:01,007:SCEM_02,000:,007:590,000,002:KG,002:PC;/</LINE>
import java.util.regex.*;
public String extractLine(String xmlSource) {
Pattern p = Pattern.compile("<LINE>(.*?)</LINE>");
Matcher m = p.matcher(xmlSource);
boolean found = m.find();
if (!found)
return null;
return m.group(1);
}
特定情況的解決方案是:
String str = "<LINE>002:OR,004:0001,002:01,002:01,007:SCEM_02,000:,007:590,000,002:KG,002:PC;/</LINE> ";
str = str.substring((str.indexOf(">")+1),str.lastIndexOf("<"));
System.out.println(str);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.