473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. xdoc.LoadXml(xresponseFromServer);
  2.  
  3.  
  4.                 XmlNode xnodes = xdoc.SelectSingleNode("/Collection/articles");
  5.                 int mediaId = 0;
  6.                 int mediaListId = 0;
  7.                 string title = "";
  8.                 DateTime modified = DateTime.Parse("2000-01-01");
  9.                 CultureInfo CI = CultureInfo.CurrentCulture;
  10.                 CultureInfo readOnlyCI = CultureInfo.ReadOnly(CI);
  11.                 const DateTimeStyles Style = DateTimeStyles.AssumeLocal;  // Assume it's local time.
  12.  
  13.                 //int mediaIdCounter = 0;
  14.                 //int newMediaCounter = 0;
  15.                 int updateMediaCounter = 0;
  16.                 int deleteMediaCounter = 0;
  17.  
  18.  
  19.                 // Ensure that we are getting a list with at least one published movie.
  20.                 if (xn != null && xnodes.ChildNodes.Count > 0)
  21.                 {
  22.                     //set publishedAtProvider=2 for all movies.(later set publishedAtProvider=1 for all mediaId's found in XML. All that still have
  23.                     //published=2 after checking the list has been unpublished. Set PublishedAtProvider=0 for unpublished movies.
  24.                     //Create a new record for each new MediaId in the XML list.
  25.                     //setPublishStatusTwo(operatorCode, country, language);
  26.  
  27.                     foreach (XmlNode node in xnodes.ChildNodes)
  28.                     {
  29.                         if (node.Name == "article")
  30.                         {
  31.                             // Loop through all Media from GetMediaList
  32.                             foreach (XmlNode childNode in node.ChildNodes)
  33.                             {
  34.                                 if (childNode.LocalName.Equals("ExternalId"))
  35.                                 {
  36.                                     mediaId = Int32.Parse(childNode.InnerText);
  37.                                     mediaIdCounter = ++mediaIdCounter;
  38.                                 }
  39.                                 else if (childNode.LocalName.Equals("title"))
  40.                                     title = childNode.InnerText;
  41.                                 else if (childNode.LocalName.Equals("modified"))
  42.                                     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
Nov 30 '10 #1
2 1727
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.
Nov 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Pradeep Kumar C | last post by:
Hi, I am new to this xml. How can I update and insert some values in existing xml document. which parser i can use for it in dot net. Whether dot net XmlTextWriter I can user for this or there is...
3
by: sho_nuff | last post by:
Question here: I have been trying to find a way to add existing nested nodes to a tree that already has nodes in it: So, my tree looks like this: -com -foo -goo
1
by: Brent Jenny | last post by:
I have an existing xml file taht looks like this. <?xml version="1.0" encoding="utf-8" ?> <Aircraft> <WCOJOItemType type="AircraftType" > <WCJOItemCode>03</WCJOItemCode>...
6
by: DWrek | last post by:
Here is my problem. I have an XML document that is returned to me by a third party service. The XML document contains results for a search but only lists a maximum of 10 results. If there are any...
1
by: Todd Beaulieu | last post by:
I want to build an XML document from a number of sub documents. As I call objects in my data structure, each would return their own ToXml(), which I want to append to the main document that I'm...
20
by: alice | last post by:
I'm doing some text swapping with javascript, got it working fine, but I would like the line to have line breaks and being a beginner, I don't even know if this is possible. So I have a line like...
2
by: cesarcesar | last post by:
Hi, XML novice here with another question. I need to add a XML node like, <child01> <child02> <text></text> <image>image 1</image> <image>image 2</image>
2
by: SM | last post by:
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this:...
1
by: SM | last post by:
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this:...
2
by: lolcheelol | last post by:
the program runs without errors, but when i try to use the changenode function, if i put anything above 2 it doesn't change the correct node. here is the source code. #include <iostream.h>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.