我有以下代码,我的消息采用 xml 格式,数据量很大。我没有收到我的消息 和 。 Xml 尖括号现已转换。我想要尖括号而不是 & 符号 lt 分号。
<createOrderRequestType xmlns:ns2="http://xmlns.oracle.com/communications/ordermanagement">
<msg><head></head>
</body>
</msg>
</createOrderRequestType>
<msg>
<head> </head>
<body> </body>
</msg>
public CreateOrderResponseType createAncillariesBySoloOrderId(String soloOrderId) {
String message = findOrderBySoloOrderId(soloOrderId);
final Pattern pattern = Pattern.compile("<msg xmlns=\"\">(.+?)</msg>", Pattern.DOTALL);
final Matcher matcher = pattern.matcher(message);
matcher.find();
String msgStr = matcher.group(1) ;
log.info("message = " + msgStr );
CreateOrderRequestType createOrderRequestType = new CreateOrderRequestType() ;
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element msg = doc.createElement("msg");
msg.setTextContent(msgStr);
doc.appendChild(msg);
createOrderRequestType.getAny().add((Element) doc.getFirstChild());
StringWriter sw1 = new StringWriter();
JAXB.marshal(createOrderRequestType, sw1);
String xmlString = sw1.toString();
log.info("xmlString = " + xmlString);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return getOSMService(osmServiceUrl).createOrder(createOrderRequestType);
}
public class CreateOrderRequestType {
@XmlAnyElement(lax = true)
protected List<Object> any;
public List<Object> getAny() {
if (any == null) {
any = new ArrayList<Object>();
}
return this.any;
}
}
最佳答案
这取决于 XSD
但是,我认为会是:
...
@XmlRootElement(name = "CreateOrderRequestType") // or probably (name = "CreateOrderRequest")
public class CreateOrderRequestType {
...
还有回复
...
@XmlRootElement(name = "CreateOrderResponseType") // or probably (name = "CreateOrderResponse")
public class CreateOrderResponseType{
...
关于java - xml尖括号改为&符号lt分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60306949/