Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My XML File Is This... SendLimit.xml

HTML
<rule name="Sendlimit">
    <interface>
        <comment></comment>
        <fixParam name="USERID" type="String"/>
        <fixParam name="Account" type="String"/>
        <fixParam name="Product" type="Tradable"/>
        <chgParam name="Buy" type="Boolean"/>
        <chgParam name="Limit_Price" type="Number"/>
        <chgParam name="Quantity" type="Number"/>
        <overviewPE name="_LME">
            <value>_LME</value>
        </overviewPE>
        <overviewPE name="IsLME">
            <value>IsLME</value>
        </overviewPE>
        <overviewPE name="Counts">
            <value>Counts[0]</value>
        </overviewPE>
        <overviewPE name="Names">
            <value>Names[0]</value>
        </overviewPE>
        <detailedPE name="_LME">
            <value>_LME</value>
        </detailedPE>
    </interface>
</rule>





I tried as i can but didn't get result as i want..

i only want to read and show value like this.....


HTML
USERID    string
Account   string
Product   tradable


As on (Means Only Values)

Pls Help
Thank You...
Posted
Comments
Jegan Thiyagesan 16-May-13 7:32am    
show us your code!
Anjanee Kumar Singh 16-May-13 7:36am    
XmlTextReader rssReader = new XmlTextReader(Convert.ToString(dir)+"\\Final.xml");
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssReader);
XmlNodeList titleList = rssDoc.GetElementsByTagName("name");
XmlNodeList urlList = rssDoc.GetElementsByTagName("type");
ListViewItem lvi = new ListViewItem();

for (int i = 0; i < titleList.Count; i++)
{
listViewStaticVar.Items.Add(titleList[i].InnerXml);
}

for (int i = 0; i < urlList.Count; i++)
{
lvi.SubItems.Add(urlList[i].InnerXml);
}

listViewStaticVar.Items.Add(lvi);
Jegan Thiyagesan 16-May-13 13:11pm    
what output are you getting for this code?
Anjanee Kumar Singh 17-May-13 1:24am    
Nothing... But no error showing too..
Anjanee Kumar Singh 16-May-13 7:36am    
This is My Code


But I want Simple Code

1 solution

I have tried to implement something what you want :

//Code that you call at some event (i.e. button_click)
XmlTextReader rssReader = new XmlTextReader(Application.StartupPath + "\\Final.xml");
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssReader);

XmlNodeList nodeList = rssDoc.DocumentElement.ChildNodes;
foreach (XmlNode childNode in nodeList)
{
      AddToListView(childNode);
}


//Method implemented to read XML and add items to list view
private void AddToListView(XmlNode node)
{
    if (node != null && node.Attributes!=null && node.Attributes.Count > 0)
    {
        ListViewItem lvi = new ListViewItem();
        if (node.Attributes["name"] != null)
        {
            lvi.Text = node.Attributes["name"].Value;
        }
        if (node.Attributes["type"] != null)
        {
            lvi.SubItems.Add(node.Attributes["type"].Value);
        }
        else
        {
            if (node.ChildNodes != null && node.ChildNodes.Count > 0)
            {
                foreach (XmlNode vnode in node.ChildNodes)
                {
                    if (vnode.Name == "value")
                    {
                        lvi.SubItems.Add(vnode.InnerText);
                        break;
                    }
                }              
            }
        }
                
        listViewStaticVar.Items.Add(lvi);
    }
            
    if (!node.HasChildNodes)
        return;

    foreach (XmlNode chnode in node.ChildNodes)
    {
        AddToListView(chnode);
    } 
}
 
Share this answer
 
Comments
Mayur Panchal 17-May-13 4:14am    
I have implemented above code..for the xml you have given.
I works fine with it. Please test it with other XMLs alos.
If u face any problems then let me know.
Anjanee Kumar Singh 17-May-13 5:48am    
Thank you Mr.Mayur_Panchal it works...
Anjanee Kumar Singh 20-May-13 7:59am    
Now i want to update the given XML file Pls help how should i do
i m not getting any clue....


thank you
Mayur Panchal 21-May-13 1:14am    
you can refer above method of reading elements. To update you just need assign innertext property of the tag you want to update or if case of attributes you need to update value of the same.
for example:(Code in above method)
if (node.Attributes["name"] != null)
{
node.Attributes["name"].Value = "NewValue";
}
Anjanee Kumar Singh 21-May-13 1:17am    
I tried sir but it change all the value whose attribute name is ["name"].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900