In order to make sure your XML matches your XSD schema you need to link it. I have done this below using XElement (LINQ to XML) and then saved the file:
XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
var userSettings = new XElement("UserSettings",
new XAttribute(XNamespace.Xmlns + "xsi", ns.NamespaceName),
new XAttribute(ns + "noNamespaceSchemaLocation", ConfigurationManager.AppSettings.Get("ChartSchemaLocation")),
new XElement("Options",
new XElement("ChartType", ChartTypes.SelectedValue),
new XElement("DrawingStyle", DrawingStyle.SelectedValue),
new XElement("Theme", Theme.SelectedValue),
new XElement("Show3D", Show3D.Checked.ToString()),
new XElement("Weighted", Weighted.Checked.ToString()),
new XElement("Vertical", Vertical.Checked.ToString()),
new XElement("DisplayTitleAxis", ShowAxisTitles.Checked.ToString())));
userSettings.Save(UserSettingsFilePath);
Monday, 30 March 2009
Generating XSD from and XML file
If you want to generate an XML schema (*.xsd) file from an existing XML file you can use the xsd.exe tool.
Go to your Visual Studio command line and type in the following:
xsd.exe C:\file.xml /outputdir:C:\
Done!
Go to your Visual Studio command line and type in the following:
xsd.exe C:\file.xml /outputdir:C:\
Done!
Friday, 27 March 2009
Navigating XElement
The XMl looks like this:
XElement root = XElement.Load("data.xml");
var answers = root.CreateNavigator().Select("/Category/Subject/Question/Answer");
Then I loop through each answer...
while (answers.MoveNext())
{
Here I convert the underlying object to an Element to get the values:
var details = answers.Current.UnderlyingObject as XElement;
Now I can access the elements I want:
var val = details.Element("Description").Value;
}
XElement root = XElement.Load("data.xml");
var answers = root.CreateNavigator().Select("/Category/Subject/Question/Answer");
Then I loop through each answer...
while (answers.MoveNext())
{
Here I convert the underlying object to an Element to get the values:
var details = answers.Current.UnderlyingObject as XElement;
Now I can access the elements I want:
var val = details.Element("Description").Value;
}
ViewState Helper
A great tool to aid in viewing the percentage of the page that is ViewState.
ASP.NET ViewState Helper
ASP.NET ViewState Helper
Subscribe to:
Posts (Atom)