I try to go over an xml file and delete some attributes , I succeed doing that but I want an option to select the one that I want to delete so I thought about a list box that will show all the attributes so that I can use their ID and Value

when I use FOR EACH statement I can use foreach (System.Xml.XmlNode child in xn) then I can use child.Attributes.Count for counting the amount of attributes and then I can loop until i reach this number ( that's what I do when I delete the nodes ) but the loop is for each node in the XML but I want to use it once just to fill the listbox please help thanks.enter image description here

here is the example XML ( Can't show the values , sorry ) what I expat to see in the list are the attribute names , as selected in red

enter image description here

<VolSurface xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <MTM Currency="" Spot="" ISIN="" Exchange="" EquityName="" CutOff="" ValuationDate="">
        <Maturity ATMFVolatility="" VarSwap="" DividendYieldPercent="" ATMSVolatility="" VolatilitySpread="" DepoRate="" SumOfDividends="" SecLendingRate="" ForwardRate="" TenorDate="" Tenor="">
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
            <Strike Put="" Call="" Vol="" Strike="" Value=""/>
有帮助吗?

解决方案

OK, found my answer !! instead of selecting a list I had to select only one node and use it's COUNT

XmlNode _Node = _Doc.SelectSingleNode("/VolSurface/MTM/Maturity");
int _CNode = _Node.Attributes.Count;

in this instance I was taking ALL the node available ( it was about 150+ nodes ) and for each node I was looping for attributes

XmlNodeList xn = _Doc.SelectNodes("/VolSurface/MTM/Maturity");

Any way , THANKS FOR THE HELP :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top