gpt4 book ai didi

java - 需要变压器功能

转载 作者:行者123 更新时间:2023-12-01 12:59:47 25 4
gpt4 key购买 nike

我正在链接到一个网络服务,一切正常。下面是我的代码。

private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = \n");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}

我不太确定transformerfactory。我现在需要做的是遍历结果并查找下面的标签。

<Table diffgr:id="Table1" >之后其中会有一些标签,例如

<rID>1212</rID>
<sNo>15677</sNo>

那么最好的方法是什么,因为有些人需要将其转换为字符串,这是必要的吗?

最佳答案

转换为文档(未选中):

      TransformerFactory tf = TransformerFactory.newInstance();  
Transformer transformer = tf.newTransformer();
DOMResult result = new DOMResult();
transformer.transform(sourceContent, result);
Document doc = (Document) result.getNode();

在文档中查找:

        String tag = "Table";
String attr = "diffgr:id";
String attrValue = "Table1";
NodeList list = doc.getElementsByTagName("Table");
Element tableNode = null;
for (int i = 0; i < list.getLength(); i++) {
tableNode = ((Element) list.item(i));
String currentAttrValue = tableNode.getAttribute(attr);
if (attrValue.equals(currentAttrValue)) {
break;
}
}
String childTag1 = "rID";
String childTag2 = "sNo";
Node child1 = (Node) tableNode.getElementsByTagName(childTag1).item(0);
Node child2 = (Node) tableNode.getElementsByTagName(childTag2).item(0);
String rIDValue = child1.getTextContent();
String sNoValue = child1.getTextContent();

关于java - 需要变压器功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com