4

xmlファイルがあり、ノードの1つに子要素を追加したいのですが、xpathがnull例外をスローする理由がわかりません。それは確かに私が間違ったxpath値を与えているためかもしれません。ここに要素を追加するためのxpathは何でしょうか:

私が使用しているXPath:

//SESSIONANALYSER/KER/MODES/NI/STATEINFORMATION[@TYPE='PREPAID']/INIT/INPUT

子要素を追加したい場所は次のとおりです。

<KER> 
    <MODES>
      <NI>
        <STATEINFORMATION TYPE="PREPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="LP6ACTIVATION">
             **<I have to add a child element here>** 

次のxmlで:

<SESSIONANALYSER>
  <AP>
    <MODES>
      <NI>
        <STATEINFORMATION TYPE="PREPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="SLN7ACTIVATION">
              <METHOD NAME="CHECKSUBSCRIBERBALANCE" PARAMETERS="SLN7" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="SLN7" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="SLN7DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="SLN7" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="jk" PARAMETERS="k" POSSIBLEACTIONS1="k" MAINTAINSESSION="h" RESPONSE="l" NEXTLEVEL=";"></METHOD>
              <METHOD NAME="SENDMESSAGE" PARAMETERS="23" POSSIBLEACTIONS1="FALLOUTONSUCCESS" MAINTAINSESSION="yes" RESPONSE="format" NEXTLEVEL="msdfm"></METHOD>
              <METHOD NAME="payments" PARAMETERS="parametervalue" POSSIBLEACTIONS1="fg,f" MAINTAINSESSION="fdjfg89" RESPONSE="ndfgm" NEXTLEVEL="msdfm"></METHOD>
              <METHOD NAME="payments" PARAMETERS="l" POSSIBLEACTIONS1="l" MAINTAINSESSION="l" RESPONSE="l" NEXTLEVEL="l"></METHOD>
              <METHOD NAME="payments" PARAMETERS="l" POSSIBLEACTIONS1="l" MAINTAINSESSION="l" RESPONSE="l" NEXTLEVEL="l"></METHOD>
              <METHOD NAME="payments" PARAMETERS="k" POSSIBLEACTIONS1="k" MAINTAINSESSION="k" RESPONSE="k" NEXTLEVEL="k"></METHOD>
              <METHOD NAME="payments" PARAMETERS="L" POSSIBLEACTIONS1="L" MAINTAINSESSION="L" RESPONSE="L" NEXTLEVEL="L"></METHOD>
              <METHOD NAME="SENDMESSAGE" PARAMETERS="23" POSSIBLEACTIONS1="FALLOUTONSUCCESS" MAINTAINSESSION="yes" RESPONSE="format" NEXTLEVEL="msdfm"></METHOD>
              <METHOD NAME="payments" PARAMETERS="12" POSSIBLEACTIONS1="FALLOUTONSUCCESS" MAINTAINSESSION="yes" RESPONSE="format" NEXTLEVEL="msvm"></METHOD>
              <METHOD NAME="SENDMESSAGE" PARAMETERS="23" POSSIBLEACTIONS1="FALLOUTONSUCCESS" MAINTAINSESSION="yes" RESPONSE="0" NEXTLEVEL="3"></METHOD>
              <METHOD NAME="SENDMESSAGE" PARAMETERS="23" POSSIBLEACTIONS1="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="format" NEXTLEVEL="3"></METHOD>
            </INPUT>
          </INIT>
          <FAILUREREGION INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="LOWBALANCE">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="1" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="SETPSOFAILED">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="2" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="UCIPDEBIT">
              <METHOD NAME="UNSETPSOINMINSAT" PARAMETERS="SLN7" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_UNSETPSO_FALSE" MAINTAINSESSION="NO" RESPONSE="-6" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="3" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="UNSETPSO">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="4" NEXTLEVEL="" />
            </INPUT>
          </FAILUREREGION>
        </STATEINFORMATION>
        <STATEINFORMATION TYPE="POSTPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="SLN7DEACTIVATION">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="5" NEXTLEVEL="" />
            </INPUT>
          </INIT>
        </STATEINFORMATION>
      </NI>
    </MODES>
  </AP>
  <TN>
    <MODES>
      <NI>
        <STATEINFORMATION TYPE="PREPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="LPC16ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LPC16" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP26ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LP26" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP49ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LP49" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LPT16ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LPT16" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP60ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LP60" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LPC16DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LPC16" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP26DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LP26" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <!--<METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />-->
            </INPUT>
            <INPUT VALUE="LP49DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LP49" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LPT16DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LPT16" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP60DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LP60" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
          </INIT>
          <FAILUREREGION INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="LOWBALANCE">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="1" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="SETPSOFAILED">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="2" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="UCIPDEBIT">
              <METHOD NAME="UNSETPSOINMINSAT" PARAMETERS="SLN7" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_UNSETPSO_FALSE" MAINTAINSESSION="NO" RESPONSE="-6" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="3" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="UNSETPSO">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="4" NEXTLEVEL="" />
            </INPUT>
          </FAILUREREGION>
        </STATEINFORMATION>
        <STATEINFORMATION TYPE="POSTPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="5" NEXTLEVEL="" />
            </INPUT>
          </INIT>
        </STATEINFORMATION>
      </NI>
    </MODES>
  </TN>
  <KER>
    <MODES>
      <NI>
        <STATEINFORMATION TYPE="PREPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="LP6ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LP6" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LPSP15ACTIVATION">
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LPSP15" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP6DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LP6" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LPSP15DEACTIVATION">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LPSP15" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="LP6SUBSCRIPTION">
              <METHOD NAME="CHECKSUBSCRIBERBALANCE" PARAMETERS="LP6" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_LOWBALANCE_INSUFFICIENTBALANCE" MAINTAINSESSION="NO" RESPONSE="-3" NEXTLEVEL="" />
              <METHOD NAME="SETPSOINUCIP" PARAMETERS="LP6" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="FIREUCIPDEBIT" PARAMETERS="LP6" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_CHARGINGFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="0" NEXTLEVEL="" />
            </INPUT>
          </INIT>
          <FAILUREREGION INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="LOWBALANCE">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="1" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="CHARGINGFAILED">
              <METHOD NAME="UNSETPSOINUCIP" PARAMETERS="LP6" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_SETPSOFAILED_FALSE" MAINTAINSESSION="NO" RESPONSE="-4" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="6" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="SETPSOFAILED">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="2" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="UCIPDEBIT">
              <METHOD NAME="UNSETPSOINMINSAT" PARAMETERS="SLN7" POSSIBLEACTIONS="FALLOUTON_FAILUREREGION_UNSETPSO_FALSE" MAINTAINSESSION="NO" RESPONSE="-6" NEXTLEVEL="" />
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="3" NEXTLEVEL="" />
            </INPUT>
            <INPUT VALUE="UNSETPSO">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="4" NEXTLEVEL="" />
            </INPUT>
          </FAILUREREGION>
        </STATEINFORMATION>
        <STATEINFORMATION TYPE="POSTPAID">
          <INIT INVALIDINPUTRESPONSE="-2">
            <INPUT VALUE="">
              <METHOD NAME="SENDMESSAGE" PARAMETERS="" POSSIBLEACTIONS="FALLOUTONSUCCESS" MAINTAINSESSION="NO" RESPONSE="5" NEXTLEVEL="" />
            </INPUT>
          </INIT>
        </STATEINFORMATION>
      </NI>
    </MODES>
  </KER>
</SESSIONANALYSER>
4

2 に答える 2

2

評価しているXPath式

//SESSIONANALYSER/KER/MODES/NI/STATEINFORMATION[@TYPE='PREPAID']/INIT/INPUT

1つだけでなく6つINPUTの要素を選択します。

これらの最初の要素の後に新しい要素を追加することを指定しました。

したがって、このXPath式を使用して、1つの(必要な)INPUT要素を選択します。

(//SESSIONANALYSER/KER/MODES/NI/STATEINFORMATION[@TYPE='PREPAID']/INIT/INPUT)[1]

ほとんどのXPathエンジンSelectNodes()は、で選択されたノードを返すメソッドを提供しNodeList、プログラマーは、単一のノードのみが選択された場合でも、このコレクションを反復処理する必要があります。これを念頭に置いてください。

于 2012-05-18T12:09:03.820 に答える
1

BHxpathになぜあるのかわかりません。

このxpathクエリは、サンプルから1つの要素のみを選択し、それが必要な要素だと思います。

/SESSIONANALYSER/KER/MODES/NI/STATEINFORMATION[@TYPE='PREPAID']
    /INIT[@INVALIDINPUTRESPONSE='-2']
    /INPUT[@VALUE='LP6ACTIVATION']
于 2012-05-18T09:20:40.867 に答える