如何在下拉菜单中获取XML元素

时间:2019-04-04 10:13:28

标签: c# asp.net xml xml-namespaces

由于父元素具有名称空间,因此无法在asp:DropDownList 中添加“ CardTypes”标签。我尝试使用XmlNodeList,但在文本框中添加值时效果很好,由于将其所有子元素都视为文本,因此无法在下拉列表中添加标签。

我尝试从具有名称空间但无法删除的标记中删除名称空间。

var namespaces = from a in doc.Descendants().Attributes()
                 where a.IsNamespaceDeclaration && a.Name != "xsi"
                 select a;   
namespaces.Remove();

但是,这对我来说效果不佳。它仅删除了最父节点的命名空间。子节点仍具有名称空间。这是我正在处理的XML文件:

<MyTableResponse>
  <Header xmlns="http://www.abcp.com/abctp">
    <Version_History>1.0</Version_History>
    <Application_Name>ShoppingExpress</Application_Name>
    <Xml_Version_No>1.0</Xml_Version_No>
    <Licence_Key>7BF26BDB-B92C-4C17-BA0D-345FBFC76619</Licence_Key>
  </Header>
  <Error xmlns="http://www.abcp.com/abctp" />
  <MasterRequest xmlns="http://www.abcp.com/abctp">
    <Village>aav</Village>
    <Culture>en</Culture>
    <Date>2019-04-06T08:51:23.8</Date>
  </MasterRequest>
  <MyTableResponse xmlns="http://www.Tagtp.com/Tagtp">
    <MyTableResponse>
      <RouteID>646</RouteID>
      <LocationID>0</LocationID>
      <RouteType>FromVillage</RouteType>
      <ChildEnabled>false</ChildEnabled>
      <InfantEnabled>false</InfantEnabled>
      <FamilyEnabled>false</FamilyEnabled>
      <OneWayEnabled>false</OneWayEnabled>
      <AdultPriceSingle>0</AdultPriceSingle>
      <AdultPriceReturn>0</AdultPriceReturn>
      <ChildPriceSingle>0</ChildPriceSingle>
      <ChildPriceReturn>0</ChildPriceReturn>
      <InfantPriceSingle>0</InfantPriceSingle>
      <InfantPriceReturn>0</InfantPriceReturn>
      <FamilyPriceSingle>0</FamilyPriceSingle>
      <FamilyPriceReturn>0</FamilyPriceReturn>
      <BookingLeadTime>0</BookingLeadTime>
      <AmendLeadTime>0</AmendLeadTime>
      <CancelLeadTime>0</CancelLeadTime>
      <BookFromDate>0001-01-01T00:00:00</BookFromDate>
      <BookToDate>0001-01-01T00:00:00</BookToDate>
      <TravelFromDate>0001-01-01T00:00:00</TravelFromDate>
      <TravelToDate>0001-01-01T00:00:00</TravelToDate>
      <PricingResponse>
        <RateID>970928</RateID>
        <PromoCodeDiscount>0.00</PromoCodeDiscount>
        <TotalNetPrice>132.00</TotalNetPrice>
        <TotalGrossPrice>132.00</TotalGrossPrice>
        <OriginalNetPrice>0</OriginalNetPrice>
        <OriginalGrossPrice>0</OriginalGrossPrice>
        <NetDifference>0</NetDifference>
        <GrossDifference>0</GrossDifference>
        <AccountType>true</AccountType>
        <AmendRestriction>true</AmendRestriction>
        <CancelRestriction>true</CancelRestriction>
        <CardTypes>
          <string>Visa</string>
          <string>MasterCard</string>
          <string>American Express</string>
          <string>Visa Debit</string>
          <string>Visa Electron</string>
        </CardTypes>
        <CurrencyCode>GBP</CurrencyCode>
        <isDiscounted>false</isDiscounted>
      </PricingResponse>
      <Stops>
        <VRStop>
          <StopID>3019</StopID>
          <StopOrder>0</StopOrder>
          <EstimatedTime>0</EstimatedTime>
          <OtaDefaultStop>false</OtaDefaultStop>
        </VRStop>
      </Stops>
      <isPrivate>0</isPrivate>
      <isMICE>0</isMICE>
      <Seats>53</Seats>
      <SeatsBooked>1</SeatsBooked>
      <SeatsAvailable>52</SeatsAvailable>
    </MyTableResponse>
  </MyTableResponse>
</MyTableResponse>

CardTypes标记内的值应位于asp:DropDownList下。

0 个答案:

没有答案