imusa
asked on
save System.Xml.XmlDocument object into native xml sql field
Hello,
I have a code to create a xml structure using System.Xml.XmlDocument class.
I want to save this datas into a native xml sql field, but I don't find the way to achive it.
Can you help me in this issue. I know there is saveTo method to save to file in a specific path, but I want to save into database.
Thanks.
I have a code to create a xml structure using System.Xml.XmlDocument class.
I want to save this datas into a native xml sql field, but I don't find the way to achive it.
Can you help me in this issue. I know there is saveTo method to save to file in a specific path, but I want to save into database.
Thanks.
XmlDocument xmldoc;
XmlNode xmlnode;
XmlElement xmlelem;
xmldoc = new XmlDocument();
//let's add the XML declaration section
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xmldoc.AppendChild(xmlnode);
//let's add the root element
xmlelem=xmldoc.CreateElement("","Sobre_B","");
xmldoc.AppendChild(xmlelem);
for (int sobre = 0; sobre < 3; sobre++) // 3 sobres
{
xmlelem = xmldoc.CreateElement("", "sobre_A", "");
xmldoc.ChildNodes.Item(1).AppendChild(xmlelem);
for (int pieza = 0; pieza < 4; pieza++) // 4 piezas (piezas)
{
xmlelem = xmldoc.CreateElement("", "pieza", "");
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).AppendChild(xmlelem);
xmlelem = xmldoc.CreateElement("", "coddos", "");
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).AppendChild(xmlelem);
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).ChildNodes.Item(0).InnerText = ((pieza+1) * (sobre+1)).ToString("00000");
xmlelem = xmldoc.CreateElement("", "cousco", "");
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).AppendChild(xmlelem);
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).ChildNodes.Item(1).InnerText = ((pieza+1) * (sobre+1)).ToString("00000") + ".01";
xmlelem = xmldoc.CreateElement("", "e_Anverso", "");
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).AppendChild(xmlelem);
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).ChildNodes.Item(2).InnerText = "c:\\anverso.jpg";
xmlelem = xmldoc.CreateElement("", "e_Reverso", "");
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).AppendChild(xmlelem);
xmldoc.ChildNodes.Item(1).ChildNodes.Item(sobre).ChildNodes.Item(pieza).ChildNodes.Item(3).InnerText = "c:\\reverso.jpg";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tanks,