Read XML by Node Name

Hello,

How can I read a xml file using Node Names:

For Example:

I could use:

objLst.item(i).childNodes.item(2).text

but instead of that, I want something like this:

objLst.item(i).childNodes.item(“reference”).text

Is it possible ? How can i do that ?

Depends on what XML parsing library you use, which depends on what language you’re programming in.

In most you can find an XPath parser though, which may be what you’re looking for.

This will help you…Try below solution.
Parsing Logic
private void ParseXML()
{
try {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(m_ConfigPath);
XmlNodeList nodeList = xmlDocument.SelectNodes(“/MainControl/ParentControl”);
int index = 0;
m_ConfigurationItems = new ConfigurationItem[nodeList.Count];
foreach (XmlNode node in nodeList) {
string controlType = node.Attributes.GetNamedItem(“ControlType”).Value;
string controlName = node.Attributes.GetNamedItem(“ControlName”).Value;
string row = node.Attributes.GetNamedItem(“Row”).Value;
string column = node.Attributes.GetNamedItem(“Column”).Value;
string placeholder = node.Attributes.GetNamedItem(“PlaceHolder”).Value;
string datasetproperty = node.Attributes.GetNamedItem(“DatasetProperty”).Value;
m_ConfigurationItems(index) = new ConfigurationItem(controlType, controlName, row, column, placeholder, datasetproperty);
index += 1;
}
}
catch (Exception ex) {
throw new Exception(ex.Message, ex);
}
}

XML Sample File
<MainControl>
<ParentControl ControlType=“TextBox” ControlName=“” Row=“” Column=“” PlaceHolder=“gdf” DatasetProperty=“DrereD”/>
<ParentControl ControlType=“TextBox” ControlName=“” Row=“” Column=“” PlaceHolder=“fgdf” DatasetProperty=“Crerted_Date”/>
<ParentControl ControlType=“Checkbox” ControlName=“” Row=“” Column=“” PlaceHolder=“fdg” DatasetProperty=“tr”/>
</MainControl>