linq to xml newbie question

M

Mike P

Can someone post some sample code that would allow me to extract
ResponseGroup refid and ResponseOption refID and selected from the
<Data> tag in the following XML :

<?xml version="1.0" encoding="utf-8"?>
<ScriptedFaqSession>
<DocumentSchema>
<DocumentInfo>
<Title>Eligibilty Assessment</Title>
<Description>
</Description>
</DocumentInfo>
<Section id="Section1">
<Question>
<Text>Where do you live?</Text>
<Help>&lt;P class=firstParagraph&gt;&amp;nbsp;Ask the client
what Local Authority that they live in and select the matching
option.&amp;nbsp; If the client lives in a Local Authority not listed,
simply select the Other Local Authority button.&lt;/P&gt;</Help>
<ResponseGroup id="AnswerGroup1" field="Trafford" selectMin="0"
selectMax="1">
<ResponseOption id="RadioButton100">
<Text>Manchester</Text>
</ResponseOption>
<ResponseOption id="RadioButton2">
<Text>Oldham</Text>
</ResponseOption>
<ResponseOption id="RadioButton3">
<Text>Rochdale</Text>
</ResponseOption>
<ResponseOption id="RadioButton102">
<Text>Tameside</Text>
</ResponseOption>
<ResponseOption id="RadioButton104">
<Text>Trafford</Text>
</ResponseOption>
<ResponseOption id="RadioButton105">
<Text>Stockport</Text>
</ResponseOption>
<ResponseOption id="RadioButton95">
<Text>Cheshire</Text>
</ResponseOption>
<ResponseOption id="RadioButton1">
<Text>Warrington</Text>
</ResponseOption>
<ResponseOption id="RadioButton101">
<Text>Halton</Text>
</ResponseOption>
<ResponseOption id="RadioButton106">
<Text>Liverpool</Text>
</ResponseOption>
<ResponseOption id="RadioButton103">
<Text>Wirral</Text>
</ResponseOption>
<ResponseOption id="RadioButton107">
<Text>Other Local Authority</Text>
</ResponseOption>
</ResponseGroup>
</Question>
</Section>
<Section id="Section5">
<Question>
<Text>Are you currently?...</Text>
<ResponseGroup id="AnswerGroup8" selectMin="0" selectMax="1">
<ResponseOption id="RadioButton20">
<Text>Employed</Text>
</ResponseOption>
<ResponseOption id="RadioButton21">
<Text>Unemployed, but not claiming a benefit</Text>
</ResponseOption>
<ResponseOption id="RadioButton157">
<Text>Unemployed for less than six months</Text>
</ResponseOption>
<ResponseOption id="RadioButton156">
<Text>Unemployed, for six to twelve months</Text>
</ResponseOption>
<ResponseOption id="RadioButton22">
<Text>Under threat of redundancy/redundant</Text>
</ResponseOption>
</ResponseGroup>
</Question>
</Section>
<Section id="Section14">
<Question>
<Text>Are you an ex-offender?</Text>
<Help>If the client refuses to answer this question, select No
as the option.</Help>
<ResponseGroup id="AnswerGroup19" selectMin="0" selectMax="1">
<ResponseOption id="RadioButton62">
<Text>Yes</Text>
</ResponseOption>
<ResponseOption id="RadioButton63">
<Text>No</Text>
</ResponseOption>
</ResponseGroup>
</Question>
</Section>
<Section id="Section24">
<TextBlock>
<Text>Yes, the client is eligible to join the ISUS Business
Start-up Programme</Text>
</TextBlock>
<HyperLink>
<Text>Test Hyperlink</Text>
<Url>http://localhost/mapittest/default.aspx</Url>
<Help>All the information you have collected will now be copied
into the enquiry form. The fewer the questions you asked, the more empty
fields you will need to complete with the client to save the enquiry
record</Help>
</HyperLink>
</Section>
<Section id="Section25">
<TextBlock>
<Text>Refer client to Business Link Universal Service on
telephone number</Text>
</TextBlock>
</Section>
<Section id="Section28">
<TextBlock>
<Text>Refer contact are as follows:

Bolton - Bolton Business Ventures - 0161
Salford - Salford 100 - 0161
Knowsley - ELECT - 0151</Text>
</TextBlock>
</Section>
<Section id="Section30">
<TextBlock>
<Text>Yes, the client is eligible to join ISUS Business Start-up
and Response to Redundancy</Text>
</TextBlock>
</Section>
<Section id="Section32">
<Question>
<Text>What is age group do you fall into?</Text>
<Help>&lt;P class=firstParagraph&gt;Ask the
client&amp;nbsp;their age&amp;nbsp;and then select the appropriate
button.&amp;nbsp; Explain that this question will&amp;nbsp;help
determine whether we can help.&amp;nbsp;&lt;/P&gt;</Help>
<ResponseGroup id="AnswerGroup33" selectMin="0" selectMax="1">
<ResponseOption id="RadioButton108">
<Text>Under 30 years</Text>
</ResponseOption>
<ResponseOption id="RadioButton109">
<Text>30 to 50 years</Text>
</ResponseOption>
<ResponseOption id="RadioButton112">
<Text>Over 50 years</Text>
</ResponseOption>
</ResponseGroup>
</Question>
</Section>
<Section id="Section38">
<Question>
<Text>What service are you looking for?</Text>
<Help>&lt;P class=firstParagraph&gt;&amp;nbsp;Listen to the
request made by the client and select the option that best reflects
their request.&lt;/P&gt;</Help>
<ResponseGroup id="AnswerGroup39" selectMin="0" selectMax="1">
<ResponseOption id="RadioButton141">
<Text>Start a business</Text>
</ResponseOption>
<ResponseOption id="RadioButton142">
<Text>Redundancy support</Text>
</ResponseOption>
<ResponseOption id="RadioButton145">
<Text>Skillworks</Text>
</ResponseOption>
<ResponseOption id="RadioButton152">
<Text>Other Service</Text>
</ResponseOption>
<ResponseOption id="RadioButton154">
<Text>Book on an Event</Text>
</ResponseOption>
<ResponseOption id="RadioButton155">
<Text>ITQ Training Course</Text>
</ResponseOption>
</ResponseGroup>
<ResponseGroup id="AnswerGroup42">
<ResponseText id="Textbox9">
<Text>Client First Name</Text>
</ResponseText>
<ResponseText id="Textbox10">
<Text>Client Last Name</Text>
</ResponseText>
<ResponseText id="Textbox11">
<Text>Client Post Code</Text>
</ResponseText>
<ResponseText id="Textbox13">
<Text>Contact Number</Text>
</ResponseText>
<ResponseText id="Textbox12">
<Text>Business Name </Text>
</ResponseText>
</ResponseGroup>
</Question>
</Section>
<Section id="Section40">
<TextBlock>
<Text>Refer contact to Gareth Tinsley on Extension XXX
(e-mail address removed)
</Text>
</TextBlock>
</Section>
<Section id="Section42">
<Question>
<Text>Where do you live?</Text>
<Help>&lt;P class=firstParagraph&gt;You need to be
quite&amp;nbsp;familiar with the towns and Local&amp;nbsp;Authorities in
each County&amp;nbsp;&lt;/P&gt;</Help>
<ResponseGroup id="AnswerGroup43" selectMin="0" selectMax="1">
<ResponseOption id="RadioButton146">
<Text>Merseyside</Text>
</ResponseOption>
<ResponseOption id="RadioButton147">
<Text>Greater Manchester</Text>
</ResponseOption>
<ResponseOption id="RadioButton148">
<Text>Cheshire</Text>
</ResponseOption>
</ResponseGroup>
</Question>
</Section>
<Section id="Section44">
<TextBlock>
<Text>Refer contact to Lynne Kavangh on Extension XXX
(e-mail address removed)</Text>
</TextBlock>
</Section>
<Section id="Section46">
<TextBlock>
<Text>Refer contact to Mandi Adams on Extension XXX
(e-mail address removed)</Text>
</TextBlock>
</Section>
<Section id="Section48">
<TextBlock>
<Text>Refer contact as follows:
</Text>
</TextBlock>
</Section>
<Section id="Section50">
<TextBlock>
<Text>Refer contact to our Rochdale Enterprise Champion </Text>
</TextBlock>
</Section>
<Section id="Section52">
<Question>
<Text>Are you any of the following?</Text>
<Help>Select those boxes that the client says YES to.&amp;nbsp;
If the client is none of the groups described, simply select "None of
the above".</Help>
<ResponseGroup id="AnswerGroup45" selectMin="0"
selectMax="unbounded">
<ResponseOption id="AnswerGroup45.CheckboxInput1">
<Text>Female</Text>
</ResponseOption>
<ResponseOption id="AnswerGroup45.CheckboxInput2">
<Text>Disabled</Text>
</ResponseOption>
<ResponseOption id="AnswerGroup45.CheckboxInput3">
<Text>Black or Minority Ethnic</Text>
</ResponseOption>
<ResponseOption id="AnswerGroup45.CheckboxInput4">
<Text>Social Enterprise</Text>
</ResponseOption>
</ResponseGroup>
<ResponseGroup id="AnswerGroup46" selectMin="0"
selectMax="unbounded">
<ResponseOption id="AnswerGroup46.CheckboxInput1">
<Text>None of the above</Text>
</ResponseOption>
</ResponseGroup>
</Question>
</Section>
<Section id="Section53">
<TextBlock>
<Text>Open our events page on CRM by clicking here</Text>
</TextBlock>
</Section>
<Section id="Section55">
<TextBlock>
<Text>Refer contact to SG Training who deliver our ITQ
Telephone number and contact is xxxx</Text>
</TextBlock>
</Section>
<Section id="Section61">
<TextBlock>
<Text>The client is eligble for Flexible New Deal if they live
in Greater Manchester. Refer client to Jan on Ext xxx email:
jan&gt;&gt;&gt;</Text>
</TextBlock>
</Section>
</DocumentSchema>
<Data>
<Section refID="Section38" sequence="1">
<ResponseGroup refID="AnswerGroup39">
<ResponseOption refID="RadioButton141" selected="true" />
<ResponseOption refID="RadioButton142" selected="false" />
<ResponseOption refID="RadioButton145" selected="false" />
<ResponseOption refID="RadioButton152" selected="false" />
<ResponseOption refID="RadioButton154" selected="false" />
<ResponseOption refID="RadioButton155" selected="false" />
</ResponseGroup>
<ResponseGroup refID="AnswerGroup42">
<ResponseText refID="Textbox9">
<Value />
</ResponseText>
<ResponseText refID="Textbox10">
<Value />
</ResponseText>
<ResponseText refID="Textbox11">
<Value />
</ResponseText>
<ResponseText refID="Textbox13">
<Value />
</ResponseText>
<ResponseText refID="Textbox12">
<Value />
</ResponseText>
</ResponseGroup>
</Section>
<Section refID="Section1" sequence="2">
<ResponseGroup refID="AnswerGroup1">
<ResponseOption refID="RadioButton100" selected="true" />
<ResponseOption refID="RadioButton2" selected="false" />
<ResponseOption refID="RadioButton3" selected="false" />
<ResponseOption refID="RadioButton102" selected="false" />
<ResponseOption refID="RadioButton104" selected="false" />
<ResponseOption refID="RadioButton105" selected="false" />
<ResponseOption refID="RadioButton95" selected="false" />
<ResponseOption refID="RadioButton1" selected="false" />
<ResponseOption refID="RadioButton101" selected="false" />
<ResponseOption refID="RadioButton106" selected="false" />
<ResponseOption refID="RadioButton103" selected="false" />
<ResponseOption refID="RadioButton107" selected="false" />
</ResponseGroup>
</Section>
<Section refID="Section52" sequence="3">
<ResponseGroup refID="AnswerGroup45">
<ResponseOption refID="AnswerGroup45.CheckboxInput1"
selected="true" />
<ResponseOption refID="AnswerGroup45.CheckboxInput2"
selected="false" />
<ResponseOption refID="AnswerGroup45.CheckboxInput3"
selected="false" />
<ResponseOption refID="AnswerGroup45.CheckboxInput4"
selected="false" />
</ResponseGroup>
<ResponseGroup refID="AnswerGroup46">
<ResponseOption refID="AnswerGroup46.CheckboxInput1"
selected="false" />
</ResponseGroup>
</Section>
<Section refID="Section24" sequence="4" />
</Data>
</ScriptedFaqSession>
 
R

RayLopez99

Can someone post some sample code that would allow me to extract
ResponseGroup refid and ResponseOption refID and selected from the
<Data> tag in the following XML :


Mike P,

See the below thread, which deals with a decorated class, but in
general you can modify it for your purposes.

In general the pseudocode template is this:

XmlTextReader reader = new XmlTextReader (...STUFF HERE...SEE YOUR
DOCUMENTATION...USUALLY A PATH + XML FILE);

//List/Object/ETC here to capture XML data. Let's call it
"YOUROBJECT" (a collection object, like a LINQ object)

//try...catch block / using blocks omitted for clarity, but you should
put them in

while (reader.Read())
{

if (reader.NodeType == XmlNodeType.Element && reader.Name ==
"ResponseOption")
{
string myIDstring = reader.GetAttribute(1); //gets first (or really
second) attribute, which might be "id="RadioButton100" or something
else like "RadioButton2"

if (myIDstring == "RadioButton100") { YOUROBJECT.Add= myIDstring;}
if (myIDstring == "RadioButton2") { YOUROBJECT.Add= myIDstring;}
etc, etc

}
}

I'm not an expert and you might want to ask in the below thread group,
but the above should work. BTW I don't think the XML file you are
reading is properly formed, but I could be wrong. However the above
should work.

RL

http://groups.google.com/group/comp...e?hl=en&lnk=gst&q=raylopez88#d278f06e55fea55e
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top