How to insert nodes in an existing xml?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nevzat Polat
    New Member
    • Nov 2010
    • 2

    #1

    How to insert nodes in an existing xml?

    My programming skills is not very good, neither is my english but I'm going to try explain my problem as good as it gets.

    My problem is that I have a search URL, that get an Xml code from an API.
    The problem is that I have to make the webrequest to the Url over 20 times.
    For that I made a for loop.

    Code:
    xdoc.LoadXml(xresponseFromServer);
    
    
                    XmlNode xnodes = xdoc.SelectSingleNode("/Collection/articles");
                    int mediaId = 0;
                    int mediaListId = 0;
                    string title = "";
                    DateTime modified = DateTime.Parse("2000-01-01");
                    CultureInfo CI = CultureInfo.CurrentCulture;
                    CultureInfo readOnlyCI = CultureInfo.ReadOnly(CI);
                    const DateTimeStyles Style = DateTimeStyles.AssumeLocal;  // Assume it's local time.
    
                    //int mediaIdCounter = 0;
                    //int newMediaCounter = 0;
                    int updateMediaCounter = 0;
                    int deleteMediaCounter = 0;
    
    
                    // Ensure that we are getting a list with at least one published movie.
                    if (xn != null && xnodes.ChildNodes.Count > 0)
                    {
                        //set publishedAtProvider=2 for all movies.(later set publishedAtProvider=1 for all mediaId's found in XML. All that still have
                        //published=2 after checking the list has been unpublished. Set PublishedAtProvider=0 for unpublished movies.
                        //Create a new record for each new MediaId in the XML list.
                        //setPublishStatusTwo(operatorCode, country, language);
    
                        foreach (XmlNode node in xnodes.ChildNodes)
                        {
                            if (node.Name == "article")
                            {
                                // Loop through all Media from GetMediaList
                                foreach (XmlNode childNode in node.ChildNodes)
                                {
                                    if (childNode.LocalName.Equals("ExternalId"))
                                    {
                                        mediaId = Int32.Parse(childNode.InnerText);
                                        mediaIdCounter = ++mediaIdCounter;
                                    }
                                    else if (childNode.LocalName.Equals("title"))
                                        title = childNode.InnerText;
                                    else if (childNode.LocalName.Equals("modified"))
                                        modified = DateTime.Parse(childNode.InnerText, readOnlyCI, Style);
    But how do I save each request to one single Xml, or just one single string?

    Thank you
  • Bryan Cheung
    New Member
    • Nov 2010
    • 55

    #2


    http://blogs.msdn.com/b/wriju/archiv...-document.aspx

    This should help you a bit.

    -B

    Comment

    • Nevzat Polat
      New Member
      • Nov 2010
      • 2

      #3
      Thanks Bryan.
      But I dont think it helps me that much.
      The solution is that in line 36, I want to take the "ExternalId " and put it somewhere else. An Xml, or a Listbox or whatever.
      The problem is that it loops through 24 times, and I cant get it to work without overwriting all the time.
      And I would also like to count all the "ExternalId " and possibly put it into a Label.

      Thank you.

      Comment

      Working...