<newAlarmReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">sheetNo=ID-0701-20230529-00073;errList=</newAlarmReturn>在这字符串中提取出sheetNo=ID-0701-20230529-00073;errList=的正则表达式应该怎么写
时间: 2024-03-16 15:42:31 浏览: 16
可以使用如下正则表达式来提取出该字符串中的sheetNo和errList:
```
sheetNo=([^;]+);errList=([^<]+)
```
这个正则表达式的含义是:匹配以 "sheetNo=" 开头,后面跟着一个或多个非分号字符,然后是 ";errList=",再后面跟着一个或多个非小于号字符。其中,括号内的部分表示需要提取出来的内容。
使用该正则表达式,可以得到两个匹配组:第一个匹配组是 "ID-0701-20230529-00073",第二个匹配组是空字符串。
相关问题
@JacksonXmlProperty,@JacksonXmlRootElement注解形式解决<LevyBlAmt xsi:nil="true" /> <PackNo xsi:nil="true" /> <GrossWt xsi:nil="true" /> <NetWt xsi:nil="true" />此数据
是的,你可以使用 `jackson-dataformat-xml` 库来解析XML数据,并且使用 `@JacksonXmlProperty` 和 `@JacksonXmlRootElement` 注解来指定节点名称和根节点名称。以下是一个示例代码:
首先,需要在项目中引入 `jackson-dataformat-xml` 库的依赖:
```xml
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.13.0</version>
</dependency>
```
然后,创建一个Java类来表示你的XML数据:
```java
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement(localName = "root")
public class MyData {
@JacksonXmlProperty(localName = "LevyBlAmt")
private String levyBlAmt;
@JacksonXmlProperty(localName = "PackNo")
private String packNo;
@JacksonXmlProperty(localName = "GrossWt")
private String grossWt;
@JacksonXmlProperty(localName = "NetWt")
private String netWt;
// getters and setters...
}
```
在这个示例中,我们使用了 `@JacksonXmlRootElement` 注解来指定根节点名称,使用 `@JacksonXmlProperty` 注解来指定节点名称。在属性上使用 `@JsonProperty` 注解可以指定Java属性名与XML节点名称的映射关系。
最后,使用 `XmlMapper` 解析XML数据:
```java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class XmlParser {
public static void main(String[] args) throws Exception {
String xml = "<root><LevyBlAmt xsi:nil=\"true\" />" +
"<PackNo xsi:nil=\"true\" />" +
"<GrossWt xsi:nil=\"true\" />" +
"<NetWt xsi:nil=\"true\" /></root>";
XmlMapper xmlMapper = new XmlMapper();
MyData data = xmlMapper.readValue(xml, MyData.class);
System.out.println(data.getLevyBlAmt()); // null
System.out.println(data.getPackNo()); // null
System.out.println(data.getGrossWt()); // null
System.out.println(data.getNetWt()); // null
}
}
```
在这个示例中,我们使用 `XmlMapper` 对象解析XML数据,并将XML数据转换成 `MyData` 对象。使用 `getLevyBlAmt()`、`getPackNo()`、`getGrossWt()`、`getNetWt()` 方法可以获取到节点的值。
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> <soapenv:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ESB_CS_QRY_USED_RESUSED_001 xmlns="http://esb-sc. yw.zj.chinamobile.com"> <reqXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <![CDATA[ <?xml version="1.0" encoding="UTF-8"?><RESP_PARAM><PUB_INFO><RETURN_RESULT>0</RETURN_RESULT><RETURN_DESC>操作成功</RETURN_DESC><OSB_SERIAL_NO>gateway-app-zt^16846071330000000001</OSB_SERIAL_NO></PUB_INFO><BUSI_INFO><GPRS_INFO><GPRS_IN>0</GPRS_IN><GPRS_OUT>0</GPRS_OUT><GPRS_OTHER>0</GPRS_OTHER><GPRS_DURA>0</GPRS_DURA><GPRS_FEE>0</GPRS_FEE></GPRS_INFO><MMS_INFO><MMS_AMOUNT>0</MMS_AMOUNT></MMS_INFO><SMS_INFO><TOTAL_MSG_NUM>15</TOTAL_MSG_NUM><OUT_MSG_NUM>0</OUT_MSG_NUM><INNER_MSG_NUM>0</INNER_MSG_NUM><MEN_MSG_NUM>15</MEN_MSG_NUM></SMS_INFO></BUSI_INFO></RESP_PARAM>]]> </reqXml> </ESB_CS_QRY_USED_RESUSED_001> </soapenv:Body> </soapenv:Envelope>
好的,以下是将该返回内容转换为 JSON 的方法:
1. 点击 Postman 中响应 Body 旁边的 `Code` 按钮,在弹出的对话框中选择 `Node.js - request` 代码片段。
2. 将代码片段中的 `body` 变量赋值为返回内容,即替换下面代码中的 `XMLRESPONSE`:
```
var body = `<xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<soapenv:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ESB_CS_QRY_USED_RESUSED_001 xmlns="http://esb-sc. yw.zj.chinamobile.com">
<reqXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?><RESP_PARAM><PUB_INFO><RETURN_RESULT>0</RETURN_RESULT><RETURN_DESC>操作成功</RETURN_DESC><OSB_SERIAL_NO>gateway-app-zt^16846071330000000001</OSB_SERIAL_NO></PUB_INFO><BUSI_INFO><GPRS_INFO><GPRS_IN>0</GPRS_IN><GPRS_OUT>0</GPRS_OUT><GPRS_OTHER>0</GPRS_OTHER><GPRS_DURA>0</GPRS_DURA><GPRS_FEE>0</GPRS_FEE></GPRS_INFO><MMS_INFO><MMS_AMOUNT>0</MMS_AMOUNT></MMS_INFO><SMS_INFO><TOTAL_MSG_NUM>15</TOTAL_MSG_NUM><OUT_MSG_NUM>0</OUT_MSG_NUM><INNER_MSG_NUM>0</INNER_MSG_NUM><MEN_MSG_NUM>15</MEN_MSG_NUM></SMS_INFO></BUSI_INFO></RESP_PARAM>
]]>
</reqXml>
</ESB_CS_QRY_USED_RESUSED_001>
</soapenv:Body>
</soapenv:Envelope>`;
```
3. 在代码片段中添加以下代码来将 XML 转换为 JSON:
```
var parseString = require('xml2js').parseString;
parseString(body, function (err, result) {
console.log(JSON.stringify(result));
});
```
4. 点击 `Send` 按钮,运行代码片段并在控制台中查看转换后的 JSON 结果。
以上就是将该返回内容转换为 JSON 的方法。希望对您有所帮助!