I have a web service which expects input in xml format and input needs to be encoded. The environment i am working on is .NET 4.5 and code behind is c#. I have to include the encoded xml input in the SOAP request and send it to the service which sends back the output as SOAP response. I could send SOAP request and receive the response but i am having trouble in sending the xml input. The input involves data from oracle. For example i have a table customer
Customer
CustomerName | key | Value |
______________________________________
AAA | Grocery | 10 |
AAA | Clothing | null |
In the above table if the value has null i need to refer to the other table with foreign key = "key" and get the value from the other table.
I want to build the xml as i get value from query. So if i query the customer table by passing "AAA", first i have to read the grocery and the value 10 and the xml should look like
<customer>
<Grocery>10</Grocery>
</customer>
Then i read the next row i see clothing then the value of clothing is null, so i would pass the orderType value (Clothing) to another table and get orderValue and append to the above xml to get the final xml
<customer>
<Grocery>10</Grocery
</Clothing>value from other table</Clothing>
</customer>
It is like building key value pair by getting values from database. For now i have code that reads all the values of a row using datareader.getValues and store it in array. I tried to create xml from the array but the problem is the xml is not getting added but is written overwritten.
using (OracleConnection conn = new OracleConnection(dbConnectionString))
{
conn.Open();
using (OracleCommand comm = new OracleCommand(query, conn))
{
using (OracleDataReader dr = comm.ExecuteReader())
{
while (dr.Read())
{
Object[] values = new Object[dr.FieldCount];
int fieldCount = dr.GetValues(values);
XElement xmlInput =
new XElement("Document",
new XElement(values[1].ToString(), values[0].ToString())
);
XElement xmlTree = new XElement("Document");
foreach (XElement e1 in xmlInput.Elements())
{
xmlTree.Add(new XElement("Document",
new XElement(columnName,rowValue)));
}
xmlInput.Add(xmlTree);
}
}
}
}
So how do i append the xml as i keep reading hey value pair in data reader?