Reputation: 115
I am currently working on a project where I have send values ("PFOID" and "Quantity") to a stored procedure in a XML
format.
the required XML format is something like this
<string>
<PFOID>04676723-2afb-49ff-9fa1-0131cabb407c</PFOID>
<Quantity>90</Quantity>
</string>
My code looks like this.
internal void UpdateQuantity(PFO pfo)
{
string pfoIds = "<PFO>" + "<PFOID>" + pfo.PFOId.ToString() + "</PFOID>" + " " + "<Quantity>" + pfo.PlannedQty.ToString() + "</Quantity>" + "</PFO>";
//pfoIds = pfoIds.Replace("<","<").Replace(">",">");
// string pfoIds = pfo.PFOId.ToString() + pfo.PlannedQty.ToString();
//XDocument d = new XDocument(pfoIds,
// new XElement
// ("PFO",
// new XElement("PFOID", pfo.PFOId.ToString()),
// new XElement("Quantity", pfo.PlannedQty.ToString())
// )
// );
List<string> pfoIdList = new List<string>();
pfoIdList.Add(pfoIds);
XmlSerializer serializer = new XmlSerializer(pfoIdList.GetType());
StringBuilder xmlString = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.Encoding = new UTF8Encoding();
XmlWriter writer = XmlWriter.Create(new StringWriter(xmlString), settings);
//XDocument xDoc = XDocument.Load(pfoIds);
//XmlNode xNode = xmlDoc.SelectSingleNode("PFOID", "Quantity");
//string onlyvalue = xNode.InnerText;
//System.Xml.Linq.XDocument xDoc = new XDocument();
////System.Xml.Linq.XNode xNode =new System.Xml.Linq.XDocument();
//XmlDocument xmlDoc = new XmlDocument();
//xmlDoc.Load(pfoIds);
//XmlNode xNode = xmlDoc.SelectSingleNode("PFOID", "Quantity");
//string onlyvalue = xNode.InnerText;
//serializer.WriteObject(writer, SelectedStoreIds.ToArray());
serializer.Serialize(writer, pfoIdList);
if (writer != null)
writer.Close();
xmlString.ToString();
{
Context.PFOValidateUpdateData(xmlString.ToString(), WebContext.Current.User.UserID, op =>
{
IsProcessing = false;
if (ValidateUpdateCompleted != null)
ValidateUpdateCompleted(this, EventArgs.Empty);
}, null);
}
}
}
}
I tried Using XmlDocument
and XmlNodes
but unfortunately silverlight system.xml assembly dont have these extensions in its library.
Can anyone help me out with this please, I would really be great full to you. Thank you very much.
It looks like this... Sorry I used white spaces between & lt; & lt; PFOID>" 04676723-2afb-49ff-9fa1-0131cabb407c & lt;/ PFOID & gt;" & lt; Quantity & gt;" 90 & lt;/Quantity & gt;"
Upvotes: 0
Views: 555
Reputation: 2245
I don't know if it is a possible solution for you, but you can try to do something like this.
// Create a DataSet with one table containing two columns.
DataSet dataSet = new DataSet("dataSet");
DataTable table = dataSet.Tables.Add("string");
table.Columns.Add("PFOID", typeof(string));
table.Columns.Add("Quantity", typeof(value));
DataRow row;
row = table.NewRow();
row["PFOID"]= "04676723-2afb-49ff-9fa1-0131cabb407c";
row["Quantity"]= 90;
table.Rows.Add(row);
// Display the DataSet contents as XML.
Console.WriteLine(dataSet.GetXml());
Upvotes: 1