It's really impossible to say exactly how to do this since to do it exactly depends too much on the database structure.
If you are pulling records that contain all these attributes you can use the XmlDocument to create a new xml doc, the XmlNode or XmlElement to create the child nodes and the XmlAttribute to create attributes and append them to the attribute collection for
a node.
Without all the details we can't give real details on how to do this.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
To create an attribute that declares a namespace with a prefix, you create an attribute where the namespace of the name of the attribute is
Xmlns,.
and the name of the attribute is the namespace prefix. The value of the attribute is the URI of the namespace.
I suggest that you can the code below:
XElement xEmp = XElement.Load(Server.MapPath("test.xml"));
//you can get the value from database ,set it to aw value //you can also get subnode value from database,and set it to your xml
XNamespace aw = "http://www.adventure-works.com";
XNamespace fc = "www.fourthcoffee.com";
XElement root = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XAttribute(XNamespace.Xmlns + "fc", "www.fourthcoffee.com"),
new XElement(fc + "Child",
new XElement(aw + "DifferentChild", "other content")
),
new XElement(aw + "Child2", "c2 content"),
new XElement(fc + "Child3", "c3 content")
);
xEmp.Add(root);
More details about how to add prefix to xml nodes ,please refer to the link below
Member
117 Points
334 Posts
creating XML file from database
Aug 04, 2014 12:24 PM|KeeEdwins|LINK
Hi all.
Can anyone please help me on how to create an xml file with attributes and the namespace from database and save in the below format.
thanks in advance
All-Star
26071 Points
5892 Posts
Re: creating XML file from database
Aug 04, 2014 12:41 PM|markfitzme|LINK
It's really impossible to say exactly how to do this since to do it exactly depends too much on the database structure.
If you are pulling records that contain all these attributes you can use the XmlDocument to create a new xml doc, the XmlNode or XmlElement to create the child nodes and the XmlAttribute to create attributes and append them to the attribute collection for a node.
Without all the details we can't give real details on how to do this.
All-Star
16806 Points
2777 Posts
Re: creating XML file from database
Aug 05, 2014 02:04 AM|Kevin Shen - MSFT|LINK
Hi KeeEdwins,
To create an attribute that declares a namespace with a prefix, you create an attribute where the namespace of the name of the attribute is Xmlns,.
and the name of the attribute is the namespace prefix. The value of the attribute is the URI of the namespace.
I suggest that you can the code below:
More details about how to add prefix to xml nodes ,please refer to the link below
http://msdn.microsoft.com/en-US/us-en/library/bb387069.aspx
Hope it can help you.
Best Regards,
Kevin Shen.