我想知道如何获取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