<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Doens.be &#187; XML</title>
	<atom:link href="http://www.doens.be/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.doens.be</link>
	<description></description>
	<lastBuildDate>Sat, 07 Jan 2012 04:20:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>XML parser namespace error</title>
		<link>http://www.doens.be/2009/09/xml-parser-namespace-error/</link>
		<comments>http://www.doens.be/2009/09/xml-parser-namespace-error/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:08:12 +0000</pubDate>
		<dc:creator>Jeroen Doens</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Ax 4.0]]></category>
		<category><![CDATA[Ax 5.0 (2009)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[X++]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.doens.be/?p=258</guid>
		<description><![CDATA[Today I tried to create the following XML-structure in Ax: 1 2 &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;personen xmlns:xdb=&#34;http://xmlns.oracle.com/xdb&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xsi:noNamespaceSchemaLocation=&#34;Personeel.xsd&#34;&#62; I wrote the following to do so: 1 2 3 4 xmlDoc = WGKFunctions::createXMLDocumentWithDeclaration&#40;#version, #encoding, #standalone&#41;; root = xmlDoc.createElement&#40;this.rootNode&#40;&#41;&#41;; ... root.setAttribute&#40;&#34;xsi:noNamespaceSchemaLocation&#34;, &#34;Personeel.xsd&#34;&#41;; But I got the following result: 1 2 &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;personen xmlns:xdb=&#34;http://xmlns.oracle.com/xdb&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Today I tried to create the following XML-structure in Ax:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;personen</span> <span style="color: #000066;">xmlns:xdb</span>=<span style="color: #ff0000;">&quot;http://xmlns.oracle.com/xdb&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:noNamespaceSchemaLocation</span>=<span style="color: #ff0000;">&quot;Personeel.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></td></tr></table></div>

<p>I wrote the following to do so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xpp" style="font-family:monospace;">xmlDoc <span style="color: #00007f;">=</span> WGKFunctions<span style="color: #00007f;">::</span><span style="color: #000000;">createXMLDocumentWithDeclaration</span><span style="color: #000000;">&#40;</span>#version<span style="color: #00007f;">,</span> #encoding<span style="color: #00007f;">,</span>  #standalone<span style="color: #000000;">&#41;</span>;
root <span style="color: #00007f;">=</span>  xmlDoc.<span style="color: #000000;">createElement</span><span style="color: #000000;">&#40;</span>this.<span style="color: #000000;">rootNode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
...
<span style="color: #000000;">root</span>.<span style="color: #000000;">setAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;xsi:noNamespaceSchemaLocation&quot;</span><span style="color: #00007f;">,</span>  <span style="color: #ff0000;">&quot;Personeel.xsd&quot;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p>But I got the following result:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;personen</span>  <span style="color: #000066;">xmlns:xdb</span>=<span style="color: #ff0000;">&quot;http://xmlns.oracle.com/xdb&quot;</span>  <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>  <span style="color: #000066;">noNamespaceSchemaLocation</span>=<span style="color: #ff0000;">&quot;Personeel.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></td></tr></table></div>

<p>As you see the &#8216;<strong>xsi:noNamespaceSchemaLocation</strong>&#8216; is replaced by &#8216;<strong>noNamespaceSchemaLocation</strong>&#8216;.</p>
<p>After some research, I found the following link: <a href="http://blogs.msdn.com/emeadaxsupport/archive/2009/06/12/xml-parser-namespace-error.aspx">http://blogs.msdn.com/emeadaxsupport/archive/2009/06/12/xml-parser-namespace-error.aspx</a></p>
<blockquote><p>You are using Microsoft Dynamics AX to create an XML Document. The code you are using to create the XML file was created for the previous version of the product and is now upgraded to Microsoft Dynamics AX 4.0 SP1.<br />
Using the method<br />
   <strong>setAttribute(&#8216;namespaceprefix:attribname&#8217;,'attribvalue&#8217;);</strong><br />
does not add the &#8220;namespaceprefix&#8221; to the final XML node.</p>
<p>The attribute name in the final XML node will be added without namespaceprefix:<br />
   <code><strong>&lt;node attribname="attribvalue" /&gt;</strong></code><br />
This is because the XML Framework was changed starting from Dynamics AX 4.0 and offers now a method that takes care about namespaces and prefixes itself. </p>
<p>So the solution is to use the following method instead: </p>
<p>   <strong>setAttribute2(&#8216;attribname&#8217;,'namespace&#8217;,'attribvalue&#8217;);</strong><br />
Please note that the &#8220;namespace&#8221; &#8211; not the &#8220;namespace prefix&#8221; has to be entered as second parameter. The XML Framework will resolve the namespace automatically to the correct namespace prefix and add it to the final XML node: </p>
<p>   <strong>&lt;node namespaceprefix:attribname=&#8221;attribvalue&#8221; /&gt;</strong></p></blockquote>
<p>So I modified my code to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xpp" style="font-family:monospace;">root.<span style="color: #000000;">setAttribute2</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;noNamespaceSchemaLocation&quot;</span><span style="color: #00007f;">,</span>  <span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><span style="color: #00007f;">,</span> <span style="color: #ff0000;">&quot;Personeel.xsd&quot;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p>and the correct XML was generated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doens.be/2009/09/xml-parser-namespace-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

