Hello,
I have been grappling with XML attribute modification for the evening and have moderate success. I am, however, struggling with the modification of an attribute if it exists, or creating a new element for the child node if it does not exist with a new entry.
Here is the XML I am using as an example:-
Here is the same XML with annotation to try and explain each section:-Code:<?xml version="1.0" encoding="utf-8"?> <report> <historic count="1110" starTime="2016-06-06T10:15:19.038Z" endTime="2012-08-24T10:15:19.038Z"> <daily> <day date="2016-06-06" count="111"></day> <day date="2016-06-07" count="222"></day> <day date="2016-06-08" count="333"></day> <day date="2016-06-09" count="444"></day> </daily> </historic> <day> <cars count="111" time="2016-06-06T10:15:12.038Z"></cars> <cars count="222" time="2016-06-07T10:15:11.038Z"></cars> <cars count="333" time="2016-06-08T10:15:10.038Z"></cars> <cars count="444" time="2016-06-09T10:15:10.038Z"> <lane id="A" count="30"></lane> <lane id="B" count="50"></lane> <lane id="C" count="364"></lane> </cars> </day> </report>
How do I read the XML into VB.NET 2015 and modify an attribute and if the day's data does not exist, create it in report/daily and report/cars and then add the new attribute?Code:<?xml version="1.0" encoding="utf-8"?> <report> ** Count = the total count of all daily totals, ie: 111+222+333+444 = 1110 ** startTime = when the file was first editted ** endTime = when the file was last editted <historic count="1110" starTime="2016-06-06T10:15:19.038Z" endTime="2012-08-24T10:15:19.038Z"> <daily> ** Day totals ** If the current day is the 2016-06-09 then the 444 total would keep increasing as I wish, ie, adding +1, or +2 etc adhoc throughout the day <day count="111" date="2016-06-06T10:15:12.038Z"></day> <day count="222" date="2016-06-07T10:15:11.038Z"></day> <day count="333" date="2016-06-08T10:15:10.038Z"></day> <day count="444" date="2016-06-09T10:15:10.038Z"> </day> </daily> </historic> <day> ** Day totals <cars count="111" time="2016-06-06T10:15:12.038Z"></cars> <lane id="A" count="0"></lane> <lane id="B" count="111"></lane> <lane id="C" count="0"></lane> <cars count="222" time="2016-06-07T10:15:11.038Z"></cars> <lane id="A" count="111"></lane> <lane id="B" count="111"></lane> <lane id="C" count="0"></lane> <cars count="333" time="2016-06-08T10:15:10.038Z"></cars> <lane id="A" count="111"></lane> <lane id="B" count="111"></lane> <lane id="C" count="111"></lane> ** Keep track of day total = 444 (30+50+364) <cars count="444" time="2016-06-09T10:15:10.038Z"> ** Keep track of each lane's total as well, so as /daily/cars/count increases but x amount, so does each lane ID and count as I pass data into it <lane id="A" count="30"></lane> <lane id="B" count="50"></lane> <lane id="C" count="364"></lane> </day> </report>
For example, how would I add one to the count attribute for the date "2016-06-06"?
and if it does not exist create a new day's data, such as:-
<day date="2017-06-06" count="1"></day>
Any pointers would be good - thank you![]()




Reply With Quote
