What I want to do:
I am trying to create an XSD file for an existing XML file.
I am using the xsd.exe tool (comes with Visual Studio).
Some elements in the XML file have access to the namespace. In some cases, the local names are the same, as shown below:
<images> <icons> <icon url="http://www.icons.com/logo.png"/> </icons> <foo:icons> <foo:foo_icon url="http://www.foo.org/pic.ico"/> </foo:icons> </images>
What I get:
Calling xsd.exe myfile.xml gives me an error: Cannot add a column named 'icons': a nested table with the same name already belongs to this DataTable.
OK, but what is the namespace used for, right? The solution to this ambiguity. If there were no namespaces, I would just call the foo_icons element instead of playing with prefixes.
What I tried:
I tried to find a way to configure xsd.exe to take namespaces into account, but not xsd /? , neither my Google queries found any answer. The /n[amespace]: Does not allow multiple namespaces to be specified.
I read Working with namespaces in an XML Schema , but I don't feel much wiser.
Do I need to create separate XSD files and embed them in eachother? xsd.exe also not used for this purpose.
I'm really not very familiar with XSD, so I probably misunderstood some of the essential concepts of the whole process. I would appreciate it if someone could point me in the right direction.
Change 1 - the following sentence of Mark Gravel:
I tried this, but I also had to rename the element (prefix) that appeared in different sections of XML (under different parent nodes), since xsd did not allow this. I had to rename it to elementOne , elementTwo , etc. I was going to rename it manually. But the XSD I received does not work anyway.
Title:
<xs:schema id="NewDataSet" targetNamespace="http://www.foo.com/bar" xmlns:mstns="http://www.foo.com/bar" xmlns="http://www.foo.com/bar" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:app1="http://www.foo.com/bar/extensions" xmlns:app2="http://www.w3.org/XML/1998/namespace">
And when I try to check the file with it, I get an error message:
Prefix 'app2' cannot be mapped to namespace name reserved for "xml" or "xmlns".
So, for what purpose xsd.exe generate it like that? How should this be fixed?