Skip to content

: cannot convert from 'string[]' to 'string' what is this error abt?

pashi

Asked Mar 7, 2007, 3:56 AM EST1 answer
Share
LinkedInX
Hi i sorry, if any big blunders i am very new to this kind of programming plese help me actually i have collected some values from xml file and i need to disply them so i wrote public string[] GetLaserProp(string laserid, string parentnode1, string childnode1) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(@"E:\Dropdown_XML\laserProp.xml"); string[] str = new string[5]; // XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName("laser"); XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName(parentnode1); //return xmlnodelst; //foreach (XmlNode.parentnode in xmlnodelst) foreach (XmlNode parentnode in xmlnodelst) { //MessageBox.Show(parentnode.Attributes.Item(0).Value); if (parentnode.Attributes.Item(0).Value == laserid) { xmldoc.LoadXml(parentnode.InnerXml); //XmlNodeList xmlchildnodelst=xmldoc.GetElementsByTagName("gauge"); XmlNodeList xmlchildnodelst = xmldoc.GetElementsByTagName(childnode1); // cmbChildLaser.Items.Clear(); foreach (XmlNode childnode in xmlchildnodelst) { for (int i = 0; i < childnode.ChildNodes.Count; i++) { //cmbChildLaser.Items.Add(childnode.ChildNodes.Item(i).Attributes.Item(0).Value); for (int j = 0; j < childnode.ChildNodes.Item(i).Attributes.Count; j++) { // MessageBox.Show( str[j]= childnode.ChildNodes.Item(i).Attributes.Item(j).Value; //cmbChildLaser.Items.Add(xmlnodelst1.Item(ii).ChildNodes.Item(0).InnerText); return str; } } } } } //return (Student []) students.ToArray();} return str;

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0

    your posting is a bit hard to read so I attempted to repost it (although the repost may have errors <g>)

    public string[] GetLaserProp(string laserid, string parentnode1, string childnode1)
    {

     XmlDocument xmldoc = new XmlDocument();
       xmldoc.Load(@"E:\Dropdown_XML\laserProp.xml");
      string[] str = new string[5];
    // XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName("laser");  
    XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName(parentnode1);
    //return xmlnodelst;
    foreach (XmlNode parentnode in xmlnodelst)
      { 
       if (parentnode.Attributes.Item(0).Value == laserid)
        {
           xmldoc.LoadXml(parentnode.InnerXml); 
        XmlNodeList xmlchildnodelst = xmldoc.GetElementsByTagName(childnode1); 
        foreach (XmlNode childnode in xmlchildnodelst)
         {
          for (int i = 0; i < childnode.ChildNodes.Count; i++)
            {
                //cmbChildLaser.Items.Add(childnode.ChildNodes.Item(i).Attributes.Item(0).Value);
             for (int j = 0; j < childnode.ChildNodes.Item(i).Attributes.Count; j++)
              {
               // MessageBox.Show( str[j]= childnode.ChildNodes.Item(i).Attributes.Itemj).Value;
               //cmbChildLaser.Items.Add(xmlnodelst1.Item(ii).ChildNodes.Item(0).InnerText);
                 return str; 
              } 
            }
      }
     }
     } //return (Student []) students.ToArray();}
    return str;

    0