使用 VB.net 和 Xmldocument 解析 XML

Parsing XML with VB.net and Xmldocument

我有几个 xml 文档正在用 VB.Net 解析。除了这一个,我能够解析所有这些。

我想从 type="route_number" 的 "incoming_did_route" 节点提取 "number"、"note" 和 "name" 的值。他们我想从子节点"extension"

中拉取"account_id"的值

下面是我正在尝试使用的 vb.net 代码:

 Dim doc As New XmlDocument()
    doc.Load("filename.xml")
    Dim nodes As XmlNodeList = doc.SelectNodes("/response/result/incoming_did_routes/incoming_did_route/*")
    Dim name As String = "", number As String = "", note As String = "", account_id As String = ""
    For Each node As XmlNode In nodes
        number = node.Attributes.GetNamedItem("number").Value
        name = node.Attributes.GetNamedItem("name").Value
        note = node.Attributes.GetNamedItem("note").Value
        account_id = node.Attributes.GetNamedItem("account_id").Value
    Next

如果我注释掉号码、姓名和备注,它将拉取 account_id。但我不知道如何获取其他值并将其缩小到仅 type="route_number".

这是 xml 文件中保存的内容:

<response method="switchvox.incomingDidRoutes.getList">
  <result>
    <incoming_did_routes total_items="4">
        <incoming_did_route type="route_number" priority="6" any_provider="1" force_fax="0" number="0000" call_type="2" note="jane doe" name="000-000-0000" id="49">
            <extension title="" type="sip" number="000" has_additional_phones="1" master_account_id="" converged="0" profile_image_link="" profile_image_id="" location="city" lang_locale="en_us" login_password_score="100" voicemail_password_score="100" phone_password_score="100" template_name="" template_id="1111" email_address="email@address.com" username="" last_name="doe" first_name="jane" type_display="Main Phone" date_created="2017-11-15 09:39:33" display="jane doe" account_id="3333" status="1" server_uuid="e28fd3d-000-jhvg6chjy7"/>
        </incoming_did_route>
        <incoming_did_route type="route_number" priority="7" any_provider="1" force_fax="0" number="0001" call_type="2" note="john doe" name="000-000-0001" id="50">
            <extension title="" type="sip" number="001" has_additional_phones="1" master_account_id="" converged="0" profile_image_link="" profile_image_id="" location="city" lang_locale="en_us" login_password_score="100" voicemail_password_score="100" phone_password_score="100" template_name="" template_id="1111" email_address="email@address.com" username="" last_name="doe" first_name="john" type_display="Main Phone" date_created="2017-11-15 09:39:33" display="jane doe" account_id="3334" status="1" server_uuid="e28fd3d-000-jhvg6chjy7"/>
        </incoming_did_route>
        <incoming_did_route type="default_route" priority="10000" id="55" sip_provider_id="000">
            <extension type="ivr" number="100" type_display="IVR" date_created="2017-08-04 11:08:53" display="Main Greeting" account_id="2" status="1" server_uuid="e28fd3d6" ivr_menu_entry_point="IVR Menu Beginning" ivr_menu_name="Main Greeting" ivr_menu_id=""/>
            <fax_extension title="" type="sip" number="003" has_additional_phones="0" master_account_id="" converged="0" profile_image_link="" profile_image_id="0" location="city" lang_locale="en_us" login_password_score="100" voicemail_password_score="100" phone_password_score="100" template_name="" template_id="1111" email_address="fax@address.com" username="" last_name="Machine" first_name="fax" type_display="Main Phone" date_created="2017-11-15 10:07:34" display="fax machine" account_id="3335" status="1" server_uuid="e28fd3d6"/>
        </incoming_did_route>
        <incoming_did_route type="catchall_unknown_route" priority="20000" id="1" action="busy"/>
    </incoming_did_routes>
  </result>
</response>

非常感谢任何帮助!

http://www.dreamincode.net/forums/topic/411041-parsing-xml-with-vbnet-and-xmldocument/page__gopid__2365610&#entry2365610

这是我找到答案的link。