我想知道如何獲取Xml文件的節點路徑。我粘貼在下面。所以我想創建一個方法,它將採用一個節點路徑並將節點路徑指向的元素的xml返回給我。從Xml獲取節點路徑
問題是假設我希望xml FormA1下的元素成員(其具有Mouser在成員/成員名稱/ BusinessNameLine1Txt下),我怎麼能得到它,因爲xml也有另一個成員元素(儘管與不同的BusinessNameLine1Txt = Mouser1)。
<ReturnState>
<ReturnDataState>
<Form6>
<Header>
<BusinessActivityCode>423690</BusinessActivityCode>
<StateOfIncorporation>
<State>DE</State>
<YearOfIncorporation>2006</YearOfIncorporation>
</StateOfIncorporation>
</Header>
<Body>
<EstTaxPmtLessRefund>492823</EstTaxPmtLessRefund>
<Overpayment>118450</Overpayment>
<OverpaymentCreditedNxtYr>118450</OverpaymentCreditedNxtYr>
<Reconciliation></Reconciliation>
<SignatureArea></SignatureArea>
<Member>
<MemberName>
<BusinessNameLine1Txt>Mouser0</BusinessNameLine1Txt>
</MemberName>
<FormA1>
<PartI-SalesFactor>
<SalesDelOrShippedOutState>31754631</SalesDelOrShippedOutState>
<TotalSales>
<Wisconsin>31754631</Wisconsin>
<TotalCompany>1965873635</TotalCompany>
</TotalSales>
<SalesFactorTotal>
<Wisconsin>31754631</Wisconsin>
<TotalCompany>1965873635</TotalCompany>
</SalesFactorTotal>
<ApportionmentPercentage>0.000000</ApportionmentPercentage>
</PartI-SalesFactor>
</FormA1>
</Member>
<Member>
<MemberName>
<BusinessNameLine1Txt>Mouser1</BusinessNameLine1Txt>
</MemberName>
<FormA1>
<PartI-SalesFactor>
<SalesDelOrShippedOutState>31754632</SalesDelOrShippedOutState>
<TotalSales>
<Wisconsin>31754632</Wisconsin>
<TotalCompany>1965873633</TotalCompany>
</TotalSales>
<SalesFactorTotal>
<Wisconsin>31754632</Wisconsin>
<TotalCompany>196587344</TotalCompany>
</SalesFactorTotal>
<ApportionmentPercentage>1.000000</ApportionmentPercentage>
</PartI-SalesFactor>
</FormA1>
</Member>
</Body>
</Form6>
</ReturnDataState>
</ReturnState>
所以,如果我是通過該方法的路徑,
ReturnState/ReturnDataState/Form6 /美體/會員/ FormA1並希望它返回
<FormA1>
<PartI-SalesFactor>
<SalesDelOrShippedOutState>31754631</SalesDelOrShippedOutState>
<TotalSales>
<Wisconsin>31754631</Wisconsin>
<TotalCompany>1965873635</TotalCompany>
</TotalSales>
<SalesFactorTotal>
<Wisconsin>31754631</Wisconsin>
<TotalCompany>1965873635</TotalCompany>
</SalesFactorTotal>
<ApportionmentPercentage>0.000000</ApportionmentPercentage>
</PartI-SalesFactor>
</FormA1>
,而不是其他FormA1在不同的Member元素下。我會怎麼做?
非常感謝!
AJ。
您如何區分您所需要的FormA1元素和您不需要的元素?你總是想要獲得第一個匹配元素嗎?還是有其他一些標準? – StriplingWarrior
聽起來像[xpath](https://msdn.microsoft.com/en-us/library/ms256115%28v=vs.110%29.aspx) –
嗨StriplingWarrior,感謝您的快速回復。這將是我面臨的挑戰之一,假設我想從第二個成員元素中檢索FormA1。我將如何能夠做到這一點? – user3375390