1. 程式人生 > 實用技巧 >一個XML解析例項

一個XML解析例項

xml內容:

"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n                                    <aiml>\n                                    <category><pattern>*充*到*</pattern><template>尊敬的使用者,請點選下面連結提交充值問題的相關資訊,我們會盡快為您確認。</template><url2 id=\"510822\" type=\"9\" title
=\"wuchao_3填寫充值不到賬表單2\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=def41fccd52c473e969b6631a76d2af7\"></url2> <tag name=\"2342342342\" id=\"106203\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>*買*到*</pattern><template>尊敬的使用者,請點選下面連結提交充值問題的相關資訊,我們會盡快為您確認。</template><url2
id=\"510822\" type=\"9\" title=\"wuchao_3填寫充值不到賬表單2\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=def41fccd52c473e969b6631a76d2af7\"></url2> <tag name=\"2342342342\" id=\"106203\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>*充值*</pattern><template>尊敬的使用者,請點選下面連結提交充值問題的相關資訊,我們會盡快為您確認。</template><url2
id=\"510822\" type=\"9\" title=\"wuchao_3填寫充值不到賬表單2\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=def41fccd52c473e969b6631a76d2af7\"></url2> <tag name=\"2342342342\" id=\"106203\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>公告</pattern><action name=\"xxx活動上線啦\" reply=\"xxx活動上線啦\"></action><template>點選下列選項,瞭解最新動態</template><url2 id=\"510825\" type=\"9\" title=\"測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f172e99a0d934aa1bdb8ea26aa605660\"></url2> <tag name=\"wuchao\" id=\"106259\"/></category><category><pattern>網路診斷</pattern><action name=\"ping\" reply=\"ping\"></action><action name=\"traceroute\" reply=\"traceroute\"></action><template>這是網路診斷</template><url2 id=\"510826\" type=\"9\" title=\"Form_big標籤\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=ff71184078964b7ebb2d86407d9a055c\"></url2> </category><category><pattern>隨機測試</pattern><url title=\"本站連結\" content=\"https://bilibili.com\" ></url> <action name=\"明天\" reply=\"明天\"></action><action name=\"最近\" reply=\"最近\"></action><template>這是隨機測試表單</template><url2 id=\"510827\" type=\"9\" title=\"測試版\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=ca8c9e23459842abb81d0de23d95ad3c\"></url2> <tag name=\"account is frozen\" id=\"119181\"/></category><category><pattern>日常測試表單</pattern><template>這是最簡單的表單</template><url2 id=\"510828\" type=\"9\" title=\"提交建議(日誌上傳)\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=b77a3aa10cd74c4788e6095fb203a7cd\"></url2> </category><category><pattern>TRACEROUTE</pattern><template>這是traceroute方式</template><tag name=\"賬號凍結\" id=\"119712\"/></category><category><pattern>反饋BUG</pattern><action name=\"活動bug\" reply=\"活動bug\"></action><action name=\"其他bug\" reply=\"其他bug\"></action><template>尊敬的客戶,請選擇您要反饋的bug型別:</template><url2 id=\"510834\" type=\"9\" title=\"Form_充值異常\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=ea6240c4bc364d7881500f8d08b72dcb\"></url2> </category><category><pattern>賬號被盜</pattern><template>尊敬的使用者,請您點選下面連結提交賬號被盜表單,我們會盡快為您找回。更新</template><url2 id=\"510835\" type=\"9\" title=\"Form_舉報非法玩家\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=d8ae1c8a37b74c0a9389adea34645e88\"></url2> </category><category><pattern>外鏈傳引數</pattern><template>測試</template><url2 id=\"510838\" type=\"9\" title=\"百度一下你就知道\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://www.baidu.com/\"></url2> <tag name=\"cheating\" id=\"63473\"/></category><category><pattern>PING</pattern><template>這是ping方式</template><tag name=\"賬號\" id=\"80942\"/></category><category><pattern>賬號被凍結</pattern><template>尊敬的玩家,請您點選下面連結提交賬號被凍結表單,我們會盡快確認並給您答覆。</template><url2 id=\"510844\" type=\"9\" title=\"Form_(Copy)賬號凍結\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" ></url2> <tag name=\"account is frozen\" id=\"119181\"/></category><category><pattern>圖片</pattern><template>圖片上傳填寫表單</template><url2 id=\"510846\" type=\"9\" title=\"上傳圖片\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=9dc4269be3464a4eb32eaeb7d5df329e\"></url2> </category><category><pattern>*建議*</pattern><url title=\"點選此處填寫意見表單\" content=\"https://aihelp.net/Elva/Forms/Fill.aspx?id=0819d585d5e04b05ba348ec451fdd863\" ></url> <template>尊敬的使用者,歡迎您提出自己的寶貴意見,也可以吐槽您的不滿,我們會用心傾聽每個使用者的聲音,並在後續的版本中體現。1</template><url2 id=\"510848\" type=\"9\" title=\"人工客服測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=2396f25dcc5a49e1bfed85864a8c4fec\"></url2> </category><category><pattern>*意見*</pattern><url title=\"點選此處填寫意見表單\" content=\"https://aihelp.net/Elva/Forms/Fill.aspx?id=0819d585d5e04b05ba348ec451fdd863\" ></url> <template>尊敬的使用者,歡迎您提出自己的寶貴意見,也可以吐槽您的不滿,我們會用心傾聽每個使用者的聲音,並在後續的版本中體現。1</template><url2 id=\"510848\" type=\"9\" title=\"人工客服測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=2396f25dcc5a49e1bfed85864a8c4fec\"></url2> </category><category><pattern>*</pattern><template>抱歉,請提交人工客訴</template><url2 id=\"510849\" type=\"9\" title=\"人工客服測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=2396f25dcc5a49e1bfed85864a8c4fec\"></url2> <alicekm id=\"510849\" type=\"wildcard\" ></alicekm> </category><category><pattern>測試場景</pattern><action name=\"特殊字元\" reply=\"特殊字元\"></action><action name=\"測試圖片和視訊\" reply=\"測試圖片和視訊\"></action><action name=\"外鏈傳引數\" reply=\"外鏈傳引數\"></action><action name=\"帶自定義URL\" reply=\"帶自定義URL\"></action><action name=\"帶日期\" reply=\"帶日期\"></action><action name=\"日常測試表單\" reply=\"日常測試表單\"></action><action name=\"隨機測試\" reply=\"隨機測試\"></action><template>這是測試要用的常用操作,請不要刪除id=(測試專用)id=</template><url2 id=\"510850\" type=\"9\" title=\"Form_人工客服\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f97ef8b4957d4fb99aa3cc8dc88d59c4\"></url2> </category><category><pattern>賬號丟失</pattern><template>尊敬的使用者,請您點選下面連結提交賬號丟失表單,我們會盡快為您核實並找回。</template><url2 id=\"510851\" type=\"9\" title=\"Form_測試建立中文\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" ></url2> </category><category><pattern>視訊</pattern><action name=\"啊大大\" reply=\"啊大大\"></action><template>阿達阿薩德</template><url2 id=\"510854\" type=\"9\" title=\"Form_測試場傳視訊\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=d0ef146c356e4cbcb4421e8e63039502\"></url2> <tag name=\"accountisfrozen\" id=\"119179\"/></category><category><pattern>賬號問題</pattern><action name=\"賬號丟失\" reply=\"賬號丟失\"></action><action name=\"賬號被凍結\" reply=\"賬號被凍結\"></action><action name=\"賬號被盜\" reply=\"賬號被盜\"></action><template>尊敬的使用者,請問選擇下列您遇到的賬號問題:</template><url2 id=\"510855\" type=\"9\" title=\"Form_提交遊戲建議\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=e181091f096b4af5bb11adb08c34a788\"></url2> <tag name=\"account is frozen\" id=\"119181\"/></category><category><pattern>DEFAULTWELCOMETEXT</pattern><action name=\"公告\" reply=\"公告\"></action><action name=\"賬號問題\" reply=\"賬號問題\"></action><action name=\"充值不到賬\" reply=\"充值不到賬\"></action><action name=\"反饋Bug\" reply=\"反饋Bug\"></action><action name=\"我要提建議\" reply=\"我要提建議\"></action><action name=\"網路診斷\" reply=\"網路診斷\"></action><action name=\"投訴舉報\" reply=\"投訴舉報\"></action><action name=\"測試場景\" reply=\"測試場景\"></action><template>尊敬的使用者,我是您的智慧小客服Elva(艾娃),歡迎來到Tryaihelp本地環境。\n您可以在螢幕底部直接輸入您的問題,也可以選擇下列服務型別提交表單給人工客服,或者點選右上角直接聯絡人工客服。112</template><url2 id=\"510856\" type=\"9\" title=\"自耦電腦\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f97ef8b4957d4fb99aa3cc8dc88d59c4\"></url2> <tag name=\"345sdgfdsdf\" id=\"106204\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>活動BUG</pattern><template>請您點選下方連結,詳細填寫bug表單,我們會盡快核實並解決您問題。</template><url2 id=\"510859\" type=\"9\" title=\"提交活動bug表單\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=308e2a7ab16a4842a7edb800fc3cb97c\"></url2> </category><category><pattern>測試圖片和視訊</pattern><url title=\"please tap here to provid:e us with more information\" content=\"https://www.baidu.com\" ></url> <action name=\"圖片\" reply=\"圖片\"></action><action name=\"視訊\" reply=\"視訊\"></action><action name=\"百度\" reply=\"百度\"></action><template>請填寫表單(帶自定義url)id=</template><url2 id=\"510860\" type=\"9\" title=\"Form_測試 專用\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f1bb03c6846b4ea08173c24b144d4352\"></url2> <tag name=\"模擬器測試\" id=\"60080\"/><tag name=\"賬號\" id=\"80942\"/></category><category><pattern>其他BUG</pattern><template>請您點選下方連結,詳細填寫bug表單,我們會盡快核實並解決您問題。</template><url2 id=\"510867\" type=\"9\" title=\"其他bug提交\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" ></url2> <tag name=\"other bug\" id=\"63474\"/></category><category><pattern>測試場景</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><action name=\"特殊字元\" reply=\"特殊字元\"></action><action name=\"測試圖片和視訊\" reply=\"測試圖片和視訊\"></action><action name=\"外鏈傳引數\" reply=\"外鏈傳引數\"></action><action name=\"帶自定義URL\" reply=\"帶自定義URL\"></action><action name=\"帶日期\" reply=\"帶日期\"></action><action name=\"日常測試表單\" reply=\"日常測試表單\"></action><action name=\"隨機測試\" reply=\"隨機測試\"></action><template>這是測試要用的常用操作,請不要刪除id=(測試專用)id=</template><url2 id=\"510850\" type=\"9\" title=\"Form_人工客服\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f97ef8b4957d4fb99aa3cc8dc88d59c4\"></url2> </category><category><pattern>外鏈傳引數</pattern><that>這是測試要用的常用操作 請不要刪除ID 測試專用 ID </that><template>測試</template><url2 id=\"510838\" type=\"9\" title=\"百度一下你就知道\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://www.baidu.com/\"></url2> <tag name=\"cheating\" id=\"63473\"/></category><category><pattern>測試圖片和視訊</pattern><that>這是測試要用的常用操作 請不要刪除ID 測試專用 ID </that><url title=\"please tap here to provid:e us with more information\" content=\"https://www.baidu.com\" ></url> <action name=\"圖片\" reply=\"圖片\"></action><action name=\"視訊\" reply=\"視訊\"></action><action name=\"百度\" reply=\"百度\"></action><template>請填寫表單(帶自定義url)id=</template><url2 id=\"510860\" type=\"9\" title=\"Form_測試 專用\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f1bb03c6846b4ea08173c24b144d4352\"></url2> <tag name=\"模擬器測試\" id=\"60080\"/><tag name=\"賬號\" id=\"80942\"/></category><category><pattern>視訊</pattern><that>請填寫表單 帶自定義URL ID </that><action name=\"啊大大\" reply=\"啊大大\"></action><template>阿達阿薩德</template><url2 id=\"510854\" type=\"9\" title=\"Form_測試場傳視訊\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=d0ef146c356e4cbcb4421e8e63039502\"></url2> <tag name=\"accountisfrozen\" id=\"119179\"/></category><category><pattern>圖片</pattern><that>請填寫表單 帶自定義URL ID </that><template>圖片上傳填寫表單</template><url2 id=\"510846\" type=\"9\" title=\"上傳圖片\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=9dc4269be3464a4eb32eaeb7d5df329e\"></url2> </category><category><pattern>日常測試表單</pattern><that>這是測試要用的常用操作 請不要刪除ID 測試專用 ID </that><template>這是最簡單的表單</template><url2 id=\"510828\" type=\"9\" title=\"提交建議(日誌上傳)\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=b77a3aa10cd74c4788e6095fb203a7cd\"></url2> </category><category><pattern>公告</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><action name=\"xxx活動上線啦\" reply=\"xxx活動上線啦\"></action><template>點選下列選項,瞭解最新動態</template><url2 id=\"510825\" type=\"9\" title=\"測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=f172e99a0d934aa1bdb8ea26aa605660\"></url2> <tag name=\"wuchao\" id=\"106259\"/></category><category><pattern>賬號問題</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><action name=\"賬號丟失\" reply=\"賬號丟失\"></action><action name=\"賬號被凍結\" reply=\"賬號被凍結\"></action><action name=\"賬號被盜\" reply=\"賬號被盜\"></action><template>尊敬的使用者,請問選擇下列您遇到的賬號問題:</template><url2 id=\"510855\" type=\"9\" title=\"Form_提交遊戲建議\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=e181091f096b4af5bb11adb08c34a788\"></url2> <tag name=\"account is frozen\" id=\"119181\"/></category><category><pattern>賬號丟失</pattern><that>尊敬的使用者 請問選擇下列您遇到的賬號問題 </that><template>尊敬的使用者,請您點選下面連結提交賬號丟失表單,我們會盡快為您核實並找回。</template><url2 id=\"510851\" type=\"9\" title=\"Form_測試建立中文\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" ></url2> </category><category><pattern>賬號被凍結</pattern><that>尊敬的使用者 請問選擇下列您遇到的賬號問題 </that><template>尊敬的玩家,請您點選下面連結提交賬號被凍結表單,我們會盡快確認並給您答覆。</template><url2 id=\"510844\" type=\"9\" title=\"Form_(Copy)賬號凍結\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" ></url2> <tag name=\"account is frozen\" id=\"119181\"/></category><category><pattern>賬號被盜</pattern><that>尊敬的使用者 請問選擇下列您遇到的賬號問題 </that><template>尊敬的使用者,請您點選下面連結提交賬號被盜表單,我們會盡快為您找回。更新</template><url2 id=\"510835\" type=\"9\" title=\"Form_舉報非法玩家\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=d8ae1c8a37b74c0a9389adea34645e88\"></url2> </category><category><pattern>*充*到*</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><template>尊敬的使用者,請點選下面連結提交充值問題的相關資訊,我們會盡快為您確認。</template><url2 id=\"510822\" type=\"9\" title=\"wuchao_3填寫充值不到賬表單2\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=def41fccd52c473e969b6631a76d2af7\"></url2> <tag name=\"2342342342\" id=\"106203\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>*買*到*</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><template>尊敬的使用者,請點選下面連結提交充值問題的相關資訊,我們會盡快為您確認。</template><url2 id=\"510822\" type=\"9\" title=\"wuchao_3填寫充值不到賬表單2\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=def41fccd52c473e969b6631a76d2af7\"></url2> <tag name=\"2342342342\" id=\"106203\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>*充值*</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><template>尊敬的使用者,請點選下面連結提交充值問題的相關資訊,我們會盡快為您確認。</template><url2 id=\"510822\" type=\"9\" title=\"wuchao_3填寫充值不到賬表單2\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=def41fccd52c473e969b6631a76d2af7\"></url2> <tag name=\"2342342342\" id=\"106203\"/><tag name=\"421412\" id=\"119491\"/></category><category><pattern>反饋BUG</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><action name=\"活動bug\" reply=\"活動bug\"></action><action name=\"其他bug\" reply=\"其他bug\"></action><template>尊敬的客戶,請選擇您要反饋的bug型別:</template><url2 id=\"510834\" type=\"9\" title=\"Form_充值異常\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=ea6240c4bc364d7881500f8d08b72dcb\"></url2> </category><category><pattern>活動BUG</pattern><that>尊敬的客戶 請選擇您要反饋的BUG型別 </that><template>請您點選下方連結,詳細填寫bug表單,我們會盡快核實並解決您問題。</template><url2 id=\"510859\" type=\"9\" title=\"提交活動bug表單\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=308e2a7ab16a4842a7edb800fc3cb97c\"></url2> </category><category><pattern>其他BUG</pattern><that>尊敬的客戶 請選擇您要反饋的BUG型別 </that><template>請您點選下方連結,詳細填寫bug表單,我們會盡快核實並解決您問題。</template><url2 id=\"510867\" type=\"9\" title=\"其他bug提交\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" ></url2> <tag name=\"other bug\" id=\"63474\"/></category><category><pattern>*建議*</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><url title=\"點選此處填寫意見表單\" content=\"https://aihelp.net/Elva/Forms/Fill.aspx?id=0819d585d5e04b05ba348ec451fdd863\" ></url> <template>尊敬的使用者,歡迎您提出自己的寶貴意見,也可以吐槽您的不滿,我們會用心傾聽每個使用者的聲音,並在後續的版本中體現。1</template><url2 id=\"510848\" type=\"9\" title=\"人工客服測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=2396f25dcc5a49e1bfed85864a8c4fec\"></url2> </category><category><pattern>*意見*</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><url title=\"點選此處填寫意見表單\" content=\"https://aihelp.net/Elva/Forms/Fill.aspx?id=0819d585d5e04b05ba348ec451fdd863\" ></url> <template>尊敬的使用者,歡迎您提出自己的寶貴意見,也可以吐槽您的不滿,我們會用心傾聽每個使用者的聲音,並在後續的版本中體現。1</template><url2 id=\"510848\" type=\"9\" title=\"人工客服測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=2396f25dcc5a49e1bfed85864a8c4fec\"></url2> </category><category><pattern>*</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><template>抱歉,請提交人工客訴</template><url2 id=\"510849\" type=\"9\" title=\"人工客服測試\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=2396f25dcc5a49e1bfed85864a8c4fec\"></url2> <alicekm id=\"510849\" type=\"wildcard\" ></alicekm> </category><category><pattern>網路診斷</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><action name=\"ping\" reply=\"ping\"></action><action name=\"traceroute\" reply=\"traceroute\"></action><template>這是網路診斷</template><url2 id=\"510826\" type=\"9\" title=\"Form_big標籤\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=ff71184078964b7ebb2d86407d9a055c\"></url2> </category><category><pattern>PING</pattern><that>這是網路診斷</that><template>這是ping方式</template><tag name=\"賬號\" id=\"80942\"/></category><category><pattern>TRACEROUTE</pattern><that>這是網路診斷</that><template>這是traceroute方式</template><tag name=\"賬號凍結\" id=\"119712\"/></category><category><pattern>隨機測試</pattern><that>尊敬的使用者 我是您的智慧小客服ELVA 艾娃 歡迎來到TRYAIHELP本地環境 您可以在螢幕底部直接輸入您的問題 也可以選擇下列服務型別提交表單給人工客服 或者點選右上角直接聯絡人工客服 112</that><url title=\"本站連結\" content=\"https://bilibili.com\" ></url> <action name=\"明天\" reply=\"明天\"></action><action name=\"最近\" reply=\"最近\"></action><template>這是隨機測試表單</template><url2 id=\"510827\" type=\"9\" title=\"測試版\" content=\"https://local.aihelp.net/elva/api/redirect\" varlist=\"\" formurl=\"https://local.aihelp.net/questionnaire/#/?formId=ca8c9e23459842abb81d0de23d95ad3c\"></url2> <tag name=\"account is frozen\" id=\"119181\"/></category>\n </aiml>"

上面的xml字串就是 aimlstory

解析方法:

getStoryJson(){
      let regcategory=/<category.+?<\/category>/gi,
          pattern=/<pattern.+?<\/pattern>/gi,
          template=/<template.+?<\/template>/gi,
          that=/<that.+?<\/that>/gi,
          alicekm=/<alicekm.*?(?:>|\/>)/gi,
          action =/<action.*?(?:>|\/>)/gi,
          url2 =/<url2\s.*?(?:>|\/>)/gi,
          url=/<url\s.*?(?:>|\/>)/gi,
          tag=/<tag.*?(?:>|\/>)/gi,
          getKey=/\s.*?=\"/g,
          getValue=/=\".*?\"(\s|\/>|\>)/g;
      let categoryArr=this.aimlstory.replace(/\r\n|\r|\n/g,'</br>').match(regcategory),botArr=[]
      // console.log(categoryArr)
      console.log(JSON.stringify(this.aimlstory))
      if(categoryArr&&categoryArr.length){
        categoryArr.forEach(cat=>{
          // console.log(cat);
          try{
            let alicekmobj={},actionobj=[],url2obj={},urlobj={},tagobj=[];
              // console.log(cat.match(cat))
            if(cat.match(url2)){
              cat.match(url2)[0].match(getKey).forEach((str,index)=>{
                if(str.includes(' id=')) url2obj['id']=cat.match(url2)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                if(str.includes(' type=')) url2obj['type']=cat.match(url2)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                if(str.includes(' title=')) url2obj['title']=cat.match(url2)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                if(str.includes(' content=')) url2obj['content']=cat.match(url2)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                if(str.includes(' varlist=')) url2obj['varlist']=cat.match(url2)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                // url2obj[str.replace(/=|\s|\"/g,'')]= cat.match(url2)[0].match(getValue)[index].replace(/=|\"|\s/g,'')
              })
            }
            if(cat.match(alicekm)){
              cat.match(alicekm)[0].match(getKey).forEach((str,index)=>{
                if(str.includes('id')) alicekmobj['id']=cat.match(alicekm)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                if(str.includes('type')) alicekmobj['type']=cat.match(alicekm)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
              })
            }
            if(cat.match(action)){
              // console.log(cat.match(action))
              let actionArrs=cat.match(action)
              actionArrs.forEach((item,i)=>{
                actionobj[i]={}
                item.match(getKey).forEach((str,index)=>{
                  if(str.includes('name')) actionobj[i]['action']=item.match(getValue)[index].replace(/=|\"\s|\"|\/>|\>/g,'')
                  if(str.includes('reply')) actionobj[i]['reply']=item.match(getValue)[index].replace(/=|\"\s|\"|\/>|\>/g,'')
                })
              })
            }
            if(cat.match(url)){
              cat.match(url)[0].match(getKey).forEach((str,index)=>{
                if(str.includes('title')) urlobj['title']=cat.match(url)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                if(str.includes('content')) urlobj['content']=cat.match(url)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
              })
            }
            if(cat.match(tag)){
              // console.log(cat.match(tag));
              // cat.match(tag)[0].match(getKey).forEach((str,index)=>{
              //   if(str.includes('id')) tagobj['id']=cat.match(tag)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
              //   if(str.includes('name')) tagobj['name']=cat.match(tag)[0].match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
              // })
              cat.match(tag).forEach((iTag,itagIndex)=>{
                let o = {};
                iTag.match(getKey).forEach((str,index)=>{
                  if(str.includes('id')) o['id']=iTag.match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                  if(str.includes('name')) o['name']=iTag.match(getValue)[index].replace(/=|\"\s|\"|\/>/g,'')
                })
                tagobj.push(o);
              })
            }
            // console.log(url2obj,alicekmobj,actionobj)
            // console.log(cat.match(pattern)[0].replace(/<\/?pattern>/g,''))
            botArr.push({
              question:cat.match(pattern)?cat.match(pattern)[0].replace(/<\/?pattern>/g,''):'',
              msg:cat.match(template)?cat.match(template)[0].replace(/<\/?template>/g,''):'',
              that:cat.match(that)?cat.match(that)[0].replace(/<\/?that>/g,''):'',
              alicekm:cat.match(alicekm)?alicekmobj:'',
              actions:cat.match(action)?actionobj:'',
              url2:cat.match(url2)?url2obj:'',
              url:cat.match(url)?urlobj:'',
              tag:cat.match(tag)?tagobj:'',
            })
          }catch(err){
            console.log(err)
          }
        })
        // console.log(botArr)
        // console.log(this.$refs.robot)
        this.aliceBot=botArr
        if(!this.$refs.robot.records.length){
          let localBotReply=this.$refs.robot.$parent.dialogueBot('DEFAULTWELCOMETEXT');
          if(localBotReply){
            let obj={//這個怎麼不用????
              msgs:localBotReply,
              contextType:2,
              question:localBotReply.question,
            }
            console.log("%c 父元件呼叫子元件的getLocalReply方法","background:green;color:#fff;");
            this.$refs.robot.getLocalReply(localBotReply,'DEFAULTWELCOMETEXT');
            if(this.$route.query.custom==='3'||this.$route.query.custom==='4'){
              this.manualTip = false
              this.newTipFlag = false
              this.params.sendLoginFlag = true
              this.$refs.robot.show()
            }
          }
        }
      }
    },