我无法通过 DOM 解析从 Xml 获取消息 ID

I'm not able to get the Message ID from Xml by DOM parse

提问人:Rakshitha N 提问时间:10/31/2023 最后编辑:James ZRakshitha N 更新时间:11/1/2023 访问量:13

问:

下面是用于获取消息 ID 的 xml

执行后,它停止在 Sysout 语句当前元素:S7:searchServiceRequest 不继续

请就此提出前进方向以及问题所在。

<?xml version="1.0" encoding="UTF-8"?>
<S7:searchServiceRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:S7="http://capabilities.nat.bt.com/xsd/ManageServiceActivation/2009/07/07" xmlns:S5="http://capabilities.nat.bt.com/xsd/ManageServiceActivation/2009/07/07/CCM/Standards/FilterSearchPattern" xmlns:header="http://wsi.nat.bt.com/2005/06/StandardHeader/" xsi:schemaLocation="http://capabilities.nat.bt.com/xsd/ManageServiceActivation/2009/07/07 C:\Users\AH00334546\Documents\ALTOVA~1\MSAWSD~1\ManageServiceActivation.20090707.xsd">
    <header:standardHeader>
        <header:e2e>
            <header:E2EDATA>LoggingJob123456</header:E2EDATA>
        </header:e2e>
        <header:serviceState>
            <header:stateCode>OK</header:stateCode>
        </header:serviceState>
        <header:serviceAddressing>
            <header:from>GTCJ</header:from>
            <header:to>
                <header:address>CSAMD</header:address>
            </header:to>
            <header:replyTo>
                <header:address>GTCJ</header:address>
            </header:replyTo>
            <header:messageId>blt06677003SearchDN_On_NOASASASAAA</header:messageId>
            <header:serviceName>http://itprogrammes.intra.bt.com/pdb/capabilities/ManageServceActivation/2009/07/07</header:serviceName>
            <header:action>ReadNOASData</header:action>
        </header:serviceAddressing>
        <header:serviceSpecification>
            <header:payloadFormat>XML</header:payloadFormat>
            <header:version>2.1</header:version>
        </header:serviceSpecification>
    </header:standardHeader>
    <S7:searchPattern>
        <S5:uniqueIdentifier>0</S5:uniqueIdentifier>
        <S5:expression>
            <S5:uniqueIdentifier>1</S5:uniqueIdentifier>
            <S5:operandOrSimpleTermOrOrderedExpressionList>orderedExpressionList</S5:operandOrSimpleTermOrOrderedExpressionList>
            <S5:orderedExpressionList>
                <S5:uniqueIdentifier>2</S5:uniqueIdentifier>
                <S5:operandOrSimpleTermOrOrderedExpressionList>simpleTerm</S5:operandOrSimpleTermOrOrderedExpressionList>
                <S5:simpleTerm>
                    <S5:name>Service</S5:name>
                    <S5:attributeName>SellerID</S5:attributeName>
                    <S5:attributeValue>3</S5:attributeValue>
                    <S5:substringType>is</S5:substringType>
                    <S5:isCaseSensitive>false</S5:isCaseSensitive>
                </S5:simpleTerm>
            </S5:orderedExpressionList>
            <S5:orderedExpressionList>
                <S5:uniqueIdentifier>2</S5:uniqueIdentifier>
                <S5:operandOrSimpleTermOrOrderedExpressionList>simpleTerm</S5:operandOrSimpleTermOrOrderedExpressionList>
                <S5:simpleTerm>
                    <S5:name>Service</S5:name>
                    <S5:attributeName>NOASCallServer</S5:attributeName>
                    <S5:attributeValue>CS560</S5:attributeValue>
                    <S5:substringType>is</S5:substringType>
                    <S5:isCaseSensitive>false</S5:isCaseSensitive>
                </S5:simpleTerm>
            </S5:orderedExpressionList>
            <S5:orderedExpressionList>
                <S5:uniqueIdentifier>3</S5:uniqueIdentifier>
                <S5:operandOrSimpleTermOrOrderedExpressionList>simpleTerm</S5:operandOrSimpleTermOrOrderedExpressionList>
                <S5:simpleTerm>
                    <S5:name>Service</S5:name>
                    <S5:attributeName>mainDN</S5:attributeName>
                    <S5:attributeValue>4418789000</S5:attributeValue>
                    <S5:substringType>is</S5:substringType>
                    <S5:isCaseSensitive>false</S5:isCaseSensitive>
                </S5:simpleTerm>
            </S5:orderedExpressionList>
            <S5:orderedExpressionList>
                <S5:uniqueIdentifier>4</S5:uniqueIdentifier>
                <S5:operandOrSimpleTermOrOrderedExpressionList>simpleTerm</S5:operandOrSimpleTermOrOrderedExpressionList>
                <S5:simpleTerm>
                    <S5:name>Service</S5:name>
                    <S5:attributeName>DestNoType</S5:attributeName>
                    <S5:attributeValue>0</S5:attributeValue>
                    <S5:substringType>is</S5:substringType>
                    <S5:isCaseSensitive>false</S5:isCaseSensitive>
                </S5:simpleTerm>
            </S5:orderedExpressionList>
        </S5:expression>
    </S7:searchPattern>
</S7:searchServiceRequest>

我的代码:

File fXmlFile = new File(filePath);
        
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
            
        doc.getDocumentElement().normalize();

      System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
            
      NodeList nList = doc.getElementsByTagName(doc.getDocumentElement().getNodeName());
                      doc.getAttributes();
      System.out.println("----------------------------"+doc.getAttributes());
      System.out.println("nList.getLength()"+nList.getLength());
    
       for (int temp = 0; temp < nList.getLength(); temp++) {

        Node nNode = nList.item(temp);
                
        System.out.println("\nCurrent Element :" + nNode.getNodeName());
                
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {

            Element eElement = (Element) nNode;

            //System.out.println("messageId : " + eElement.getAttribute("stan:messageId"));
            msgId= eElement.getElementsByTagName(childtagName).item(0).getTextContent();
            
            System.out.println("tag value : " + eElement.getElementsByTagName(childtagName).item(0).getTextContent());
            
            
        }
    }
   
    return msgId;
  }

}
Java DOM XML 解析

评论


答: 暂无答案