本文介绍了动态查询元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨....这是我的情况: 我有一个xml文档,我在树视图中成功显示。 

Hi .... here is my situation:  I've got an xml document that I'm successfully displaying in a treeview. 

XML是这样的:

< LOAN的xmlns = QUOT; HTTP://www.something.com/A" version =" 1.0">

  < APPLICANTS selected_product_borrower_id =" 0">

    < APPLICANT is_declined =" N">

        < ID_CARD card_type ="" />
$
        < ID_CARD2 card_type ="" />
$
        < CURRENT_ADDRESS occupancy_status =" BUYING" >

            < LOOSE_ADDRESS street_address_1 ="" />

        < / CURRENT_ADDRESS>

       < PREVIOUS_ADDRESS occupancy_status =""  />
$
        < FINANCIAL_INFO>&
            < CURRENT_EMPLOYMENT employ_months =" 1"  />
$
            < PREVIOUS_EMPLOYMENT monthly_income =" 0.00"  />
$
            < MONTHLY_INCOME monthly_income_base_salary =" 0000.00" />
$
            < MONTHLY_DEBT monthly_liability =" 0000.00"  />
$
        < / FINANCIAL_INFO>

        < REFERENCE first_name =""姓氏=""&NBSP; />
$
        < REFERENCE first_name =""姓氏=""&NBSP; />
$
        < CONTACT_INFO preferred_contact_method =" HOME"  />
$
        < ASSETS />

        < DECLARATION has_outstanding_judgement =""  />
$
        < MAILING_ADDRESS city =""状态= QUOT;"&NBSP; />
$
        < SPOUSE is_declined =" N" >

            < ID_CARD card_type =""  />
$
            < ID_CARD2 card_type =""  />
$
            < CURRENT_ADDRESS occupancy_status =" BUYING" >&$ b&b                < LOOSE_ADDRESS street_address_1 ="" />
$
            < / CURRENT_ADDRESS>&
            < PREVIOUS_ADDRESS occupancy_status ="" />
$
            < FINANCIAL_INFO>               < CURRENT_EMPLOYMENT employ_months =" 3"  />               < MONTHLY_INCOME monthly_income_base_salary =" 0000.00"  />               < MONTHLY_DEBT monthly_liability =" 0.00"  />
$
            < / FINANCIAL_INFO>

       < / SPOUSE>

    < / APPLICANT>

  < / APPLICANTS>

< / LOAN>

<LOAN xmlns="http://www.something.com/A" version="1.0">
  <APPLICANTS selected_product_borrower_id="0">
    <APPLICANT is_declined="N">
        <ID_CARD card_type="" />
        <ID_CARD2 card_type="" />
        <CURRENT_ADDRESS occupancy_status="BUYING" >
            <LOOSE_ADDRESS street_address_1=""/>
        </CURRENT_ADDRESS>
       <PREVIOUS_ADDRESS occupancy_status=""  />
        <FINANCIAL_INFO>
            <CURRENT_EMPLOYMENT employed_months="1"  />
            <PREVIOUS_EMPLOYMENT monthly_income="0.00"  />
            <MONTHLY_INCOME monthly_income_base_salary="0000.00" />
            <MONTHLY_DEBT monthly_liability="0000.00"  />
        </FINANCIAL_INFO>
        <REFERENCE first_name="" last_name=""  />
        <REFERENCE first_name="" last_name=""  />
        <CONTACT_INFO preferred_contact_method="HOME"  />
        <ASSETS />
        <DECLARATION has_outstanding_judgement=""  />
        <MAILING_ADDRESS city="" state=""  />
        <SPOUSE is_declined="N" >
            <ID_CARD card_type=""  />
            <ID_CARD2 card_type=""  />
            <CURRENT_ADDRESS occupancy_status="BUYING" >
                <LOOSE_ADDRESS street_address_1="" />
            </CURRENT_ADDRESS>
            <PREVIOUS_ADDRESS occupancy_status="" />
            <FINANCIAL_INFO>
                <CURRENT_EMPLOYMENT employed_months="3"  />
                <MONTHLY_INCOME monthly_income_base_salary="0000.00"  />
                <MONTHLY_DEBT monthly_liability="0.00"  />
            </FINANCIAL_INFO>
       </SPOUSE>
    </APPLICANT>
  </APPLICANTS>
</LOAN>

当用户点击我想要的树中的节点时显示该节点的所有属性。所以..例如,如果用户点击"CURRENT_EMPLOYMENT",对于SPOUSE如何动态到达该节点? 

When the user clicks on a node in the tree I want to display all the attributes for that node. So .. for example if the user clicks on "CURRENT_EMPLOYMENT" for the SPOUSE how to I dynamically get to that node? 

我知道使用LINQ我可以执行以下操作:

I know using LINQ I could do the following:

var query = from xDocCData.Elements中的XElement r(ns +" APPLICANTS")。元素(ns +" APPLICANT")。元素(ns +" SPOUSE")。元素(ns +" FINANCIAL_INFO")

                       选择r.Element(ns +" CURRENT_EMPLOYMENT");

var query = from XElement r in xDocCData.Elements(ns + "APPLICANTS").Elements(ns + "APPLICANT").Elements(ns + "SPOUSE").Elements(ns + "FINANCIAL_INFO")
                        select r.Element(ns + "CURRENT_EMPLOYMENT");

但如何动态构建相同的查询,而不知道用户将点击哪个节点?

but how do I build that same query dynamically not knowing what node the user will click on?

 

提前致谢......

Thanks in advance ......

推荐答案

Pawel


这篇关于动态查询元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 03:52