title: Generating an XSD file with xsd.exe tool from an XML file with multiple namespaces
body: <p><strong>What I want to do:</strong></p>
  
  <p>I am trying to generate an XSD file for an existing XML file.</p>
  
  <p>I'm using the <code>xsd.exe</code> tool (shipped with Visual Studio).</p>
  
  <p>Some of the elements in the XML file are namespace-qualified. In some cases local names are the same, just as below:</p>
  
  <pre><code>&lt;images&gt;
    &lt;icons&gt;
      &lt;icon url="http://www.icons.com/logo.png"/&gt;     
    &lt;/icons&gt;
    &lt;foo:icons&gt;
      &lt;foo:foo_icon url="http://www.foo.org/pic.ico"/&gt;
    &lt;/foo:icons&gt;
  &lt;/images&gt;
  </code></pre>
  
  <p><strong>What I am getting:</strong></p>
  
  <p>Calling <code>xsd.exe myfile.xml</code> gives me an error: <code>Cannot add a column named 'icons': a nested table with the same name already belongs to this DataTable.</code></p>
  
  <p>OK but that's what the namespace is for, isn't it? Resolving ambiguity like that. If there was no  namespaces, I would just call the element <code>foo_icons</code> instead of toying with prefixes.</p>
  
  <p><strong>What I tried:</strong></p>
  
  <p>I tried looking for a way to configure <code>xsd.exe</code> so that it takes namespaces into consideration, but neither <code>xsd /?</code> nor my google queries revealed any answer. The <code>/n[amespace]:</code> parameter does not allow for specifying multiple namespaces. </p>
  
  <p>I've read <a href="http://msdn.microsoft.com/en-us/library/ms950796.aspx" rel="nofollow">Working with Namespaces in XML Schema</a> but I don't feel much wiser.</p>
  
  <p>Do I have to create separate XSD files and embed them in eachother? It doesn't deal with using <code>xsd.exe</code> for this purpose, either.</p>
  
  <p>I'm really not too familiar with XSD, so I am probably misunderstanding some essential concepts about the whole process. I'd appreciate if someone could point me in the right direction.</p>
  
  <p><strong>Edit 1 - following Marc Gravell's suggestion:</strong></p>
  
  <p>I tried that, but I also had to rename a (prefixed) element which appeared in different sections of the XML (under different parent nodes) as <code>xsd</code> would not allow that. I had to rename it to <code>elementOne</code>, <code>elementTwo</code> etc. I was going to rename it back manually. But the XSD I got does not work anyway.</p>
  
  <p>The header is:</p>
  
  <pre><code>&lt;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"&gt;
  </code></pre>
  
  <p>And when I'm trying to validate a file with it, I'm getting an error:</p>
  
  <p><code>Prefix 'app2' cannot be mapped to namespace name reserved for "xml" or "xmlns".</code></p>
  
  <p>So, with what purpose has <code>xsd.exe</code> generated it like that? How should it be fixed?</p>