我正在使用 xml 文件“SavedWSDL.txt”,其中的一些部分在下面给出......
...
<wsdl:message name="LookUpTransactionResponse">
<wsdl:part name="LookUpTransactionReturn" type="impl:ArrayOf_xsd_anyType"/>
</wsdl:message>
<wsdl:message name="LookUpTransactionRequest"></wsdl:message>
<wsdl:message name="creditResponse">
<wsdl:part name="creditReturn" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="creditRequest">
<wsdl:part name="amount" type="xsd:float"/>
<wsdl:part name="password" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="debitRequest">
<wsdl:part name="amount" type="xsd:float"/>
<wsdl:part name="password" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="debitResponse">
<wsdl:part name="debitReturn" type="xsd:int"/>
</wsdl:message>
...
我已经编写了下面给出的java代码,应该使用什么来获取wsdl的子节点名称:名为“debitRequest”的消息标记
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Ex2 {
public static void main(String[] args) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("D:/SavedWSDL.txt");
doc.getDocumentElement().normalize();
NodeList nodelist = doc.getElementsByTagName("wsdl:message");
//System.out.println("No. of Nodes: "+nodelist.getLength());
for(int i=0;i<nodelist.getLength();i++){
Node node=nodelist.item(i);
String valueOfTag=node.getAttributes().getNamedItem("name").getNodeValue();
if(valueOfTag.equalsIgnoreCase("debitrequest")){
if(node.hasChildNodes()){
NodeList childNList=node.getChildNodes();
//System.out.println("No. of Childs: "+node.getChildNodes().getLength());
//System.out.println(node.getAttributes().getNamedItem("name").getNodeValue());
}
else{
System.out.println("NO CHILD FOUND for: "+valueOfTag);
}
}
}
} catch(Exception io) {
io.printStackTrace();
}
}
}