K
kevin_Eld
I have the following xml:
<message>
<envelope>
<body key="" value="" />
</envelope>
</message>
I have associated an xsd to this xml in order to use the
XmlDataDocument and give me the
possibility to access the data through a dataset in the manner below
specified:
DataSet ds = XmlDataDocument.DataSet;
When I try to add an element of type "body" to this xml file, this tag
is added to the node
"message" while I want to add it to the node "envelope".
Here is the code which I use to do this task:
DataRow dr = ds.Tables["body"].NewRow();
dr["key"]=126;
dr["value"]="example";
ds.Tables["body"].Rows.Add(dr);
and here is the resulting xml:
<message>
<envelope>
<body key="" value="" />
</envelope>
<body key="126" value="example" />
</message>
while I want the following result:
<message>
<envelope>
<body key="" value="" />
<body key="126" value="example" />
</envelope>
</message>
Last but not least when I try to get the attribute values of the node
inserted in the xml by
the previous code I don't have any problem even if the xsd doesn't
allow a "body" tag out of
the "envelope" tag. For example:
foreach(DataRow row in ds.Tables["body"].Rows )
{
if (row[0].ToString() == "126")
{
myVariable = row[1].ToString();
break;
}
}
How can I avoid to append the node inserted by code to the
root node using the dataset and its related classes ? How can I insert
the new node
correctly inside the envelope element (always using datasets) ?
Every suggestion will be appreciate,
thanks in advance
<message>
<envelope>
<body key="" value="" />
</envelope>
</message>
I have associated an xsd to this xml in order to use the
XmlDataDocument and give me the
possibility to access the data through a dataset in the manner below
specified:
DataSet ds = XmlDataDocument.DataSet;
When I try to add an element of type "body" to this xml file, this tag
is added to the node
"message" while I want to add it to the node "envelope".
Here is the code which I use to do this task:
DataRow dr = ds.Tables["body"].NewRow();
dr["key"]=126;
dr["value"]="example";
ds.Tables["body"].Rows.Add(dr);
and here is the resulting xml:
<message>
<envelope>
<body key="" value="" />
</envelope>
<body key="126" value="example" />
</message>
while I want the following result:
<message>
<envelope>
<body key="" value="" />
<body key="126" value="example" />
</envelope>
</message>
Last but not least when I try to get the attribute values of the node
inserted in the xml by
the previous code I don't have any problem even if the xsd doesn't
allow a "body" tag out of
the "envelope" tag. For example:
foreach(DataRow row in ds.Tables["body"].Rows )
{
if (row[0].ToString() == "126")
{
myVariable = row[1].ToString();
break;
}
}
How can I avoid to append the node inserted by code to the
root node using the dataset and its related classes ? How can I insert
the new node
correctly inside the envelope element (always using datasets) ?
Every suggestion will be appreciate,
thanks in advance