EDN Admin
Well-known member
I am attempting to get element values from an XML file to use in populating a value object. Im close, but it isnt working.
Here is some sample xml test data:
<pre class="prettyprint" style=" <response>
<payload class="java.util.RandomAccessSubList
<l class="list
<alert>
<alertGeneratedTS>1345824941330</alertGeneratedTS>
<alertTimeoutTS>1346429741330</alertTimeoutTS>
<personId>ceb3e65a-7793-41fe-9f45-d7a5f5ca33c9</personId>
<type>AGELIMITALERT</type>
<ageLimit>35</ageLimit>
<friendAge>42</friendAge>
<profileId>9129dd10-b874-4736-94b3-db788a5e41ab</profileId>
<friendId>d4895179-c720-4d24-baff-7bbdb833a40b</friendId>
</alert>
<alert>
<alertGeneratedTS>1345824941330</alertGeneratedTS>
<alertTimeoutTS>1346429741330</alertTimeoutTS>
<personId>ceb3e65a-7793-41fe-9f45-d7a5f5ca33c9</personId>
<type>AGELIMITALERT</type>
<ageLimit>35</ageLimit>
<friendAge>42</friendAge>
<profileId>9129dd10-b874-4736-94b3-db788a5e41ab</profileId>
<friendId>5eca2a10-7bd0-4ef8-abe1-8a7b7e96aad7</friendId>
</alert>
<alert>
<alertGeneratedTS>1345824941331</alertGeneratedTS>
<alertTimeoutTS>1346429741331</alertTimeoutTS>
<personId>ceb3e65a-7793-41fe-9f45-d7a5f5ca33c9</personId>
<type>AGELIMITALERT</type>
<ageLimit>35</ageLimit>
<friendAge>42</friendAge>
<profileId>9129dd10-b874-4736-94b3-db788a5e41ab</profileId>
<friendId>fe0eaf59-69cf-4eff-8240-ba3da365c1a5</friendId>
</alert>
</l>
<offset>0</offset>
<size>3</size>
<expectedModCount>1</expectedModCount>
</payload>
</response>[/code]
<br/>
Here is some sample test code that isnt working"
<pre class="prettyprint" style=" [TestMethod]
[DeploymentItem(@"TestDataWebAlertTestData.xml", "TestData")]
public void CanProcessDataHubPreprocessWebService()
{
// ARRANGE
var rqst = new EventPreprocessorRequest();
var xml = XElement.Load(@"TestDataWebAlertTestData.xml");
var alerts = from alert in xml.Element("payload")
.Element("l")
.Elements(@"alert")
select alert;
foreach (var alertdtl in alerts)
{
var data = from e in alertdtl.Elements() select e;
var xrefid = (from x in data.Elements("personId") select x.Value).ToString();
var subtype = (from s in data.Elements("type") select s.Value).ToString();
var alert = new AlertInfo
{
CommonId = new Guid(xrefid),
PartnerId = "SafetyWeb",
PartnerReferenceId = 0,
Type = "WebMonitoringAlert",
SubType = subtype,
Details = alertdtl.ToString()
};
rqst.Alerts.Add(alert);
}
// [snipped for brevity]
}[/code]
<br/>
IOW, I am attempting to get the xrefid and subtype values for each alert element, but not sure how to do it.
Plus, I think my LINQ code could be simplified, but not sure how to do that either.
<br/>
<br/>
View the full article
Here is some sample xml test data:
<pre class="prettyprint" style=" <response>
<payload class="java.util.RandomAccessSubList
<l class="list
<alert>
<alertGeneratedTS>1345824941330</alertGeneratedTS>
<alertTimeoutTS>1346429741330</alertTimeoutTS>
<personId>ceb3e65a-7793-41fe-9f45-d7a5f5ca33c9</personId>
<type>AGELIMITALERT</type>
<ageLimit>35</ageLimit>
<friendAge>42</friendAge>
<profileId>9129dd10-b874-4736-94b3-db788a5e41ab</profileId>
<friendId>d4895179-c720-4d24-baff-7bbdb833a40b</friendId>
</alert>
<alert>
<alertGeneratedTS>1345824941330</alertGeneratedTS>
<alertTimeoutTS>1346429741330</alertTimeoutTS>
<personId>ceb3e65a-7793-41fe-9f45-d7a5f5ca33c9</personId>
<type>AGELIMITALERT</type>
<ageLimit>35</ageLimit>
<friendAge>42</friendAge>
<profileId>9129dd10-b874-4736-94b3-db788a5e41ab</profileId>
<friendId>5eca2a10-7bd0-4ef8-abe1-8a7b7e96aad7</friendId>
</alert>
<alert>
<alertGeneratedTS>1345824941331</alertGeneratedTS>
<alertTimeoutTS>1346429741331</alertTimeoutTS>
<personId>ceb3e65a-7793-41fe-9f45-d7a5f5ca33c9</personId>
<type>AGELIMITALERT</type>
<ageLimit>35</ageLimit>
<friendAge>42</friendAge>
<profileId>9129dd10-b874-4736-94b3-db788a5e41ab</profileId>
<friendId>fe0eaf59-69cf-4eff-8240-ba3da365c1a5</friendId>
</alert>
</l>
<offset>0</offset>
<size>3</size>
<expectedModCount>1</expectedModCount>
</payload>
</response>[/code]
<br/>
Here is some sample test code that isnt working"
<pre class="prettyprint" style=" [TestMethod]
[DeploymentItem(@"TestDataWebAlertTestData.xml", "TestData")]
public void CanProcessDataHubPreprocessWebService()
{
// ARRANGE
var rqst = new EventPreprocessorRequest();
var xml = XElement.Load(@"TestDataWebAlertTestData.xml");
var alerts = from alert in xml.Element("payload")
.Element("l")
.Elements(@"alert")
select alert;
foreach (var alertdtl in alerts)
{
var data = from e in alertdtl.Elements() select e;
var xrefid = (from x in data.Elements("personId") select x.Value).ToString();
var subtype = (from s in data.Elements("type") select s.Value).ToString();
var alert = new AlertInfo
{
CommonId = new Guid(xrefid),
PartnerId = "SafetyWeb",
PartnerReferenceId = 0,
Type = "WebMonitoringAlert",
SubType = subtype,
Details = alertdtl.ToString()
};
rqst.Alerts.Add(alert);
}
// [snipped for brevity]
}[/code]
<br/>
IOW, I am attempting to get the xrefid and subtype values for each alert element, but not sure how to do it.
Plus, I think my LINQ code could be simplified, but not sure how to do that either.
<br/>
<br/>
View the full article