Xml Attribute not showing up on ListBox - C# -


Whenever this package tries to add title information and other attributes, the property exists and the appropriate package is selected

This code is:

  Private zero category-list view list selected (object sender, SelectionChangedEventArgs e) {XmlDocument LoadPackageList = New XmlDocument (); // removes the "Select a category" text and refreshes the form packagelist_listbox. Items.Remove (SelectaCategory_listbox); If (categorylist_listview.SelectedItem == WWW_listviewitem) {LoadPackageList.Load ("www.xml"); XmlNodeList WWWPackageList = LoadPackageLocate. Select node ("/ package / *"); Int countinodes = 0; Foreach (XmlNode WWW Packages in WWWPackList) {// Cycling through all the packages and doing them on a string, this packaging adds to countdowns ++; Packageatil [countinid] = WWW Packages.Attributes ["title"]. ToString (); PackageInfo [COUNTININED] = WWW package. Attribute ["info"] Toasting (); PackageDownloadUrl [countthenodes] = WWWPackages.Attributes ["downloadurl"]. ToString (); Package tag [countinid] = WWW package. Attribute ["tag"]. Toasting (); Packagelist_listbox.Items.Add (PackageTitle [countthenodes]); } Refresh (packagelist_listbox); }}  

This removes errors on PackageTitle [countthenodes] = WWWPackages.Attributes ["title"]. ToString ();

XML file:

<> pre & lt; Package & gt; & Lt; Firefox Title = "Mozilla Firefox" tag = "www Firefox Web Browser Mozilla" info = "http://google.com" downloadurl = "http://firefox.com" & gt; & Lt; / Firefox & gt; & Lt; / Packages & gt;

Variables have been declared

  public string [] package tag; Public string [] PackageTitle; Public string [] PackageInfo; Public string [] PackageDownloadUrl;  

Good, the first problem is That is not to call ToString () on XmlAttribute which you want. You should use the value property However, I do not believe that as long as the data does not appear as long as you have not shown it, then NullReferenceException is happening. Here is a small but complete program that works fine:

  using the system; Using System.Xml; Class test {static zero principal () {XmlDocument doc = New XmlDocument (); Doc.Load ("test.xml"); XmlNodeList List = Doctor. Selection node ("/ package / *"); Forex currency (XmlNode node in the list) {Console.WriteLine (node ​​properties ["title"]. Value);  

Options:

  • Your real XML actually contains an element without the

title attribute

  • Maybe PackageTitle is zero?
  • This can help you a production ideally should avoid using it GUI - I can not see anything here that is likely to be GUI-specific.

    If you can tell us more about PackageTitle and how this is happening initial, which would be very helpful, how do you see it as if you got any element Are you going to grow as much? Or is it an array that is started for a bigger size, so that you ever expect to find an element?


    Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    php - Multiple Select with Explode: only returns the word "Array" -

    php - jQuery AJAX Post not working -