Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use XSLT to update the second document to match the element names you're expecting. That way, you don't have to handle the different element names in the code.</p> <p>Transform the second document using XSLT, something like:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="@* | node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="//name_person"&gt; &lt;name&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/name&gt; &lt;/xsl:template&gt; &lt;xsl:template match="//surname_person"&gt; &lt;surname&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/surname&gt; &lt;/xsl:template&gt; &lt;xsl:template match="//address_person"&gt; &lt;address&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/address&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>It apply this programatically to your document, in C#, you could do:</p> <pre class="lang-cs prettyprint-override"><code>XslCompiledTransformtransform = new XslCompiledTransform(); transorm.Load("update.xsl"); transorm.Transform("source.xml","new.xml"); </code></pre> <p>In VB:</p> <pre class="lang-vb prettyprint-override"><code>Dim transform As XslTransform transform = New XslTransform() transform .Load("update.xsl") transform .Transform("source.xml", "new.xml") </code></pre> <p>The result will then be the element names will match across both documents, and you could then run your deserializer on the XML without having to worry about handling mismatched element names.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload