[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Select an XML node with specific DateTime in attribute StartDateTime

Posted on 2010-11-08
4
Medium Priority
?
795 Views
Last Modified: 2012-05-10
I have the following test:

[Test]
        public void FindTransactionByStartDateTime()
        {
            DateTime purchaseDate = new DateTime(2010, 7, 30, 15, 2, 8, 73);
            string customerId = "0460660450261";
            string xml = @"<GetHouseHoldFilteredTransactionsResponse xmlns='http://www.retalix.com/HQLWebServices'><GetHouseHoldFilteredTransactionsResult Status='Ok' /><out_HouseHoldTransactions><Transactions><Transaction xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' StoreId='6066' PosDateTime='2010-07-30' PosId='12' TranId='102' StartDateTime='2010-07-30T15:02:08.73' ClubCardId='0460660450261' CreatedAt='2010-07-30' UpdatedBy='1' TotalAmount='0.9900' StoreName='CH WOESTE' /></Transactions></out_HouseHoldTransactions></GetHouseHoldFilteredTransactionsResponse>";
            string transactionXml = SlipServiceLoyalty.GetTransactionXml(xml, customerId, purchaseDate);
            Assert.IsNotNullOrEmpty(transactionXml);
        }

public static string GetTransactionXml(string xml, string customerId, DateTime purchaseDate)
        {
            string date = purchaseDate.ToString("yyyy-MM-ddTHH:mm:ss.FF");

            XDocument doc = XDocument.Parse(xml);
            var results = (from t in doc.Descendants("{http://www.retalix.com/HQLWebServices}Transaction")

                           where IsMatchAttribute(t, "ClubCardId", customerId)
                           where (IsMatchAttribute(t, "StartDateTime", purchaseDate.ToString("yyyy-MM-ddTHH:mm:ss.FFF")) ||
                              IsMatchAttribute(t, "StartDateTime", purchaseDate.ToString("yyyy-MM-ddTHH:mm:ss.FF")))
                           select t).ToList();

            var result = results.FirstOrDefault();

            LogManager.GetCurrentClassLogger().DebugFormat("Found {0} transactions for customerId={1}", results.Count, customerId);
            return result != null ? result.ToString() : String.Empty;
        }

        private static bool IsMatchAttribute(XElement e, string attributeName, string value)
        {
            return (string)e.Attribute(attributeName) == value;
        }

Please bare in mind that the date could have FFF or FF format. I would like to catch both. My problem is that the condition on the date doesn't find the attribute StartDateTime.
0
Comment
Question by:breezback
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Nirmalan Nagenthiran earned 1200 total points
ID: 34090728
When you use
purchaseDate.ToString("yyyy-MM-ddTHH:mm:ss.FF") --> out put is 2010-07-30T15:02:08.07

Similarly
purchaseDate.ToString("yyyy-MM-ddTHH:mm:ss.FFF") --> out put is 2010-07-30T15:02:08.073

that is the reason it doesn't show the proper match.

Or else you can change this line like this
DateTime purchaseDate = new DateTime(2010, 7, 30, 15, 2, 8, 730); after this it works well

Also you can refer http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#fSpecifier for more details


0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 800 total points
ID: 34090732
You are passing 73 milliseconds as the value
>> DateTime purchaseDate = new DateTime(2010, 7, 30, 15, 2, 8, 73);
You should be passing 730 instead
Check with
DateTime purchaseDate = new DateTime(2010, 7, 30, 15, 2, 8, 730);
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 34090744
Sorry NNirmalan....didn't mean to repeat you..was near simulteneous
0
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 34090810
It's fine arif_eqbal.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question