Click here to Skip to main content
14,602,559 members
Rate this:
Please Sign up or sign in to vote.
See more:
how can i retrieve a name of a xml child node into array list. i have a array list like:
  <item1 id="1"> Text </item1>
  <item2 id="2"> Text </item2>

I want ArrayList contain only child node name like: item1, item2. please help me in this..
Updated 10-Oct-11 20:32pm
Ankur\m/ 11-Oct-11 2:31am
Why don't you put some effort, read about System.Xml namespace, and try the suggestions out.
You have been asking similar questions again. :doh:
Rate this:
Please Sign up or sign in to vote.

Solution 1

you can use XMLDocument or XMLReader class, let see the example of XMLDocuemnt

Arraylist ArrList = new Arraylist(); 
System.XML.XMLDocument objDom = new System.XML.XMLDocument();
objDom.load(//xml file path);
xmlNodeList XNList = objDom.getElementByTagName("items");
for each (xmlNode XN in XNList)
   for(int i=0; i< XN.childNodes.count; i++)
Member 8214635 11-Oct-11 1:16am
it store a "items" in arraylist not a item1 & item2. please help in this.
koolprasadd 11-Oct-11 2:11am
i have update solution please check
nil_25_12 31-May-14 3:12am
how to do this fro multiple items
Rate this:
Please Sign up or sign in to vote.

Solution 2

string strCategoryId;
XmlDocument oXMLDoc = null;
XmlNodeList oXMLNodeList;

//..this is your connection method, Admin is class Name in which method is define

oXMLDoc = oAdmin.GetPartyDetails();
oXMLNodeList = oXMLDoc.GetElementsByTagName("ABC");
if ((oXMLDoc.ChildNodes.Count >= 1) && (oXMLNodeList.Count > 0))

cboParty.Items.Add(new ListItem("-- Select Category --", "0"));
for (int intLoop = 0; intLoop <= oXMLNodeList.Count - 1; intLoop++)
strCategoryId = oXMLDoc.GetElementsByTagName("ABC").Item(intLoop).InnerText;
cboParty.Items.Add(new ListItem(strCategoryId));

ABC.Items.Add(new ListItem("No Category, Please add."));
Rate this:
Please Sign up or sign in to vote.

Solution 3

create, read and write xml file through c# asp .net

//default.cs file

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;

public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)

    public void Xml_Insert()
            XmlDocument xmlDoc = new XmlDocument();

            // Write down the XML declaration
            XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            // Create the root element
            XmlElement rootNode = xmlDoc.CreateElement("CategoryList");
            xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);

            // Create a new <Category> element and add it to the root node
            XmlElement parentNode = xmlDoc.CreateElement("Category");

            // Set attribute name and value!
            parentNode.SetAttribute("ID", "01");


            // Create the required nodes
            XmlElement mainNode = xmlDoc.CreateElement("MainCategory");
            XmlElement descNode = xmlDoc.CreateElement("Description");
            XmlElement activeNode = xmlDoc.CreateElement("Active");

            // retrieve the text 
            XmlText categoryText = xmlDoc.CreateTextNode("XML");
            XmlText descText = xmlDoc.CreateTextNode("This is a list my XML articles.");
            XmlText activeText = xmlDoc.CreateTextNode("true");

            // append the nodes to the parentNode without the value

            // save the value of the fields into the nodes

            // Save to the XML file

            Response.Write("XML file created");
    public void Xml_update()
        XmlDocument xmlDoc = new XmlDocument();

        XmlNodeList nodeList = xmlDoc.SelectNodes("/CategoryList/Category[@ID='01']");
        nodeList[0].ChildNodes[0].InnerText = "Deepak";
        nodeList[0].ChildNodes[1].InnerText = "Pooja";
        nodeList[0].ChildNodes[2].InnerText = "Ashok";

        // Don't forget to save the file
        Response.Write("XML File updated!");


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">


// xml file

<?xml version="1.0" encoding="utf-8"?>
  <Category ID="01">
Member 8214635 11-Oct-11 1:44am
i dont understand

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100