代码之家  ›  专栏  ›  技术社区  ›  Nrodgers1987

用VB解析XML。net和Xmldocument

  •  0
  • Nrodgers1987  · 技术社区  · 7 年前

    我有一些xml文档正在用VB解析。网我能够解析除此之外的所有内容。

    我想从“incoming\u did\u route”节点中提取“number”、“note”和“name”的值,其中type=“route\u number”。我想从子节点“extension”中提取“account\u 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
    

    如果我注释掉number、name和note,它将提取account\u id。但我不知道如何获取其他值并将其缩小到type=“route\u 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>
    

    非常感谢您的帮助!

    1 回复  |  直到 7 年前
    推荐文章