Hi Peter,
This is about as concise as I can get. All other code around it is just
fluff. What I didn't want to do is to make a verbose message and you fall
asleep half way through.
Let me add a sample of the actual XML that I am using...
For the xq, I am using...
<?xml version="1.0" encoding="UTF-8"?>
<form name="MEFS 106" application-name="MEFS 106">
<submit id-dashed="AJX-AAE-B5Q-J4" email="myemail@myemailcom"
phone="+441234567890"/>
<field type="checkbox" name="p1_additional_audit">false</field>
<field type="textfield" name="p1_sealing_plier_no" normalized-score="1"
resemblance-score="1">abc123</field>
<field type="textfield" name="p1_date_of_audit" normalized-score="1"
resemblance-score="1">12/03/2008</field>
<field type="textfield" name="p1_manual_no" normalized-score="1"
resemblance-score="1"></field>
</form>
For the xmap, I am using...
<?xml version="1.0" encoding="utf-8" ?>
<application id="MEFS106">
<database DBName="Audit" TableName="MFS10" />
<mapping DBField="Email" XMLField="submit:email" />
<mapping DBField="Phone" XMLField="submit
![Stick Out Tongue :p :p](/styles/default/custom/smilies/tongue.gif)
hone" />
<mapping DBField="Additional_Audit" XMLField="p1_additional_audit" />
<mapping DBField="Sealing_Plier_No" XMLField="p1_sealing_plier_no" />
<mapping DBField="Date_of_Audit" XMLField="p1_date_of_audit" />
<mapping DBField="Manual_No" XMLField="p1_manual_no" />
</application>
So, xmap reads the xml above (application). It loops through the mapping
fields. For the email, it picks out "submit:email". The left side is to tell
me it is not in a xq 'field' but in the zq 'submit' field.
xmap then loops through the mapping rows. It picks out in this example,
Additional_Audit, which has an XMLField attribute of p1_additional_audit.
So, the xmap describes the xq and which field I want the value from,
xmap.XMLField = 'p1_additional_audit' tells me that I want the value 'false'
from xq.p1_additional_audit and that xmap.XMLField = 'submit:email' tells me
that I want the value '(e-mail address removed)' from the xq.submit.email. (Note,
only items with : get their values from the attributes.)
The problem area I appear to have is...
if (mapItem.XMLField.Contains(":"))
{
string[] xField = mapItem.XMLField.Split(':');
fieldValue.Append("'" + xq.Select(d =>
xField[1]) + "'");
}
I don't yet fully understand the .Select() part and how to use it to get
what I want.
Does this help make it any clearer. My apologies for missing stuff out. I
don't know what else I can add.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Peter Duniho said:
Hi Peter,
Let me start again...
As I wrote, you should post a concise-but-complete code example that
reliably demonstrates what you're trying to do.
[...]
foreach (var mapItem in xmap.First().Mappings)
{
if (mapItem.XMLField.Contains(":"))
{
string[] xField =
mapItem.XMLField.Split(':');
fieldValue.Append("'" + xq.Select(d =>
xField[1]) + "'");
}
else
{
fieldValue.Append("'" +
xq.First().Fields.Where(a => a.Name == mapItem.XMLField).First() + "'");
}
}
In my foreach loop, I am trying to append to fieldValue. The value in
xField
will be something like... form:email, (this is from the xmap query).
Now,
What I need to do is to get the value held in the Value field from the xq
query. Basically, the xq query holds all the values. The xmap query
defines
where in the xq query to get my value. So, for example... I need to get
the
value " me@myemailcom " from the row which has the Name = "email". The
text
in Name is what I am putting into the fieldValue.Append.
I still don't really understand what the problem is.
In the code you posted, the case that appears to be the
"default"/"nameless"/whatever case seems to have the kind of code you
need. In particular, you get the first generated "form" query result
(presumably that's used as the default), and then query the fields for the
one that matches the name of the field of interest, and then finally you
take the first result (presumably the normal situation is for there to be
only one result).
For the qualified scenario (i.e. instead of just "email", you have
"formName:email") you can just use a similar technique for your "xq"
enumeration, adding a ".Where(a => a.Name == xField[0])" between the "xq"
and ".First()", to ensure you're selecting from the correct "form" element
of the original data.
But, as I said, because you haven't posted a concise-but-complete code
example, I may still yet misunderstand the question. You really should
post an actual concise-but-complete code sample. Otherwise, you'll just
get random stabs in the dark, which may or may not be helpful.
Pete