parse xml with c#

  • Thread starter Thread starter Policy standard local admin account with Active Di
  • Start date Start date
P

Policy standard local admin account with Active Di

Guest
Hello

I have tried to create a code to parse an information contains in a xml file which is configured the structure below:

it has the main node <Codecs>

then, it has two childs nodes, <VideoCodecs> and <AudioCodecs>

I created a frame which has a textBox, a Button and Listview

what I try to do is put the value of the attribut PCMA in the textbox that I want to show on the listview


this is my code

private void button1_Click(object sender, EventArgs e)
{
if (searchInput.Text != null && searchInput.Text.Length >= 3)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\mis documentos\c#\xml\SipServer2.config");

foreach (XmlNode node in doc.DocumentElement)
{


string name = node.Attributes[0].InnerText;
if (name == searchInput.Text)
{
foreach (XmlNode child in node.ChildNodes)
{
searchResults.Items.Add(child.InnerText);
}
}

}


} else
{
MessageBox.Show("Invalid input");
searchInput.Text = string.Empty;
searchInput.Focus();

}

}
}
}

But when I executed the visual studio says:

"sYSTEM.iNDEXouToFrANGEexCEPTION


I will appreciate any help


<?xml version="1.0"?>
<!-- WARNING: Those configuration represent the the default values for Sipelia SIP Server -->
<!-- WARNING: It is very recommended to make a backup of this file before doing any changes -->
<Codecs>
<VideoCodecs>
<Codec Name="H263-1998" Enabled="True"/>
<Codec Name="H264" Enabled="True" KeyframeGenerationInterval="4"/>
<Codec Name="H263" Enabled="True"/>
</VideoCodecs>
<AudioCodecs>
<Codec Name="PCMA" Enabled="True"/>
<Codec Name="PCMU" Enabled="True"/>
<Codec Name="telephone-event" Enabled="True"/>
<Codec Name="iLBC" Enabled="True"/>
<Codec Name="G722" Enabled="True"/>
<Codec Name="GSM" Enabled="True"/>
<Codec Name="SPEEX_Narrowband" Enabled="False"/>
<Codec Name="SPEEX_Wideband" Enabled="True"/>
<Codec Name="SPEEX_Ultrawideband" Enabled="True"/>
<Codec Name="L16" Enabled="False"/>
<Codec Name="L16_44_1" Enabled="True"/>
<Codec Name="G728" Enabled="False"/>
<Codec Name="G723" Enabled="False"/>
<Codec Name="G726-16" Enabled="True"/>
<Codec Name="G726-24" Enabled="False"/>
<Codec Name="G726-32" Enabled="False"/>
<Codec Name="G726-40" Enabled="False"/>
<Codec Name="G729" Enabled="False"/>
</AudioCodecs>
</Codecs>

Continue reading...
 

Similar threads

P
Replies
0
Views
78
Policy standard local admin account with Active Di
P
P
Replies
0
Views
65
Policy standard local admin account with Active Di
P
K
Replies
0
Views
64
kocsism
K
Back
Top