473,387 Members | 1,549 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,387 software developers and data experts.

Can't quite parse XML correctly - please help

Hi,

I have the following code that reads an XML document. I want it to delete
nodes where the date is less than today. It *almost* works (please see the
output below the code). How can I make the <Data /> element completely
disappear for those first 3 nodes that were earlier than the current date?

XmlDocument doc = new XmlDocument();
doc.Load(ConfigurationManager.AppSettings["keyXML"]);

XmlNode nodVDIData = doc.FirstChild;
XmlNode nodData = nodVDIData.FirstChild;

while (nodData != null)
{
XmlNode element = nodData.SelectSingleNode("TimeEventStart");
string s2 = element.InnerText;
DateTime dtm = XmlConvert.ToDateTime(s2,
XmlDateTimeSerializationMode.Local);

if (dtm < DateTime.Now)
nodData.RemoveAll();

nodData = nodData.NextSibling;
}

context.Response.ContentType = "text/xml";
XmlWriter writer = XmlWriter.Create(context.Response.OutputStream);
writer.WriteRaw(nodVDIData.OuterXml);

---------------------------------

<?xml version="1.0" encoding="utf-8" ?>
- <VDIData>
<Data />
<Data />
<Data />
- <Data>
<TimeEventStart>2006-05-06T20:00:00.0000000-07:00</TimeEventStart>
<TimeEventEnd>2006-03-06T22:00:00.0000000-07:00</TimeEventEnd>
<GroupName>DDD</GroupName>
</Data>
- <Data>
<TimeEventStart>2006-05-06T13:00:00.0000000-07:00</TimeEventStart>
<TimeEventEnd>2006-03-06T15:00:00.0000000-07:00</TimeEventEnd>
<GroupName>EEE</GroupName>
</Data>
</VDIData>
Apr 11 '06 #1
1 1346
Try deleting the node from the VDIData node:

(watch for typos)

nodVDIData.RemoveChild(nodData);

Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
1
by: Esteban Felipe | last post by:
Hi, thanks for reading. I hope to find some help here before I commit suicide because this is driving me crazy. Please excuse me if this looks like a long post, but I hope that a complete...
3
by: Mark | last post by:
I am looking for an example of using checkboxes in a repeater control where the checkbox state is persisted from page to page. Thank you, Mark
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
by: TulasiKumar | last post by:
hi all, i have one requirement in my project.The requirement is i want to fix some domain sites in TcpIp like proxy servers behaviour.When ever end user passing the inforamtion of that domain...
13
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone...
14
by: salad | last post by:
XML seems to be a hot technology buzzword. And it appears XML is supported in A2003. I am wondering if it could be used in the following scenario. I create an order record for the customer. ...
4
by: Peter | last post by:
Hi all, I am searching through directories trying to find the prefix to a number of files. Unfortunately the files don't have a standard naming convention yet. So some of them appear as:...
4
by: fbrewster | last post by:
I'm writing an HTML parser and would like to use Internet Explorers DOM parser. Can I use Internet Explorers DOM parser through a web service? thanks for the help
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.