Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate XML attribute in a repeating section using Microsoft.BizTalk.Streaming.ValueMutator
    primarykey
    data
    text
    <p>I have a problem where I am attempting to update a set of attributes with a fixed value contained within a repeating section of an XML document using the <code>Microsoft.BizTalk.Streaming.ValueMutator</code>. </p> <p>For example the XML document which I am attempting to update contains the following input:</p> <pre><code>&lt;ns0:TestXML xmlns:ns0="http://Test.Schemas"&gt; &lt;ns0:NodeA&gt; &lt;ns0:NodeB&gt; &lt;ns0:alpha Id="1" Value="Apple" Type=""&gt;&lt;/ns0:alpha&gt; &lt;ns0:alpha Id="2" Value="Banana" Type=""&gt;&lt;/ns0:alpha&gt; &lt;ns0:alpha Id="3" Value="Car" Type=""&gt;&lt;/ns0:alpha&gt; &lt;ns0:alpha Id="4" Value="Duck" Type=""&gt;&lt;/ns0:alpha&gt; &lt;/ns0:NodeB&gt; &lt;/ns0:NodeA&gt; &lt;/ns0:TestXML&gt; </code></pre> <p>The code which I am attempting to use to update the XML document is:</p> <pre><code>XmlDocument xDocInput = new XmlDocument(); XmlDocument xDocOutput = new XmlDocument(); string inputFileName = @"C:\Input.xml"; string outputFileName = @"C:\Output.xml"; string newValue = "fruit"; string xpathToUpdate = "/*[namespace-uri()='http://Test.Schemas']/*[local-name()='NodeA']/*[local-name()='NodeB']/*[@Type]"; xDocInput.Load(inputFileName); using (MemoryStream memstream = new MemoryStream()) { xDocInput.Save(memstream); memstream.Position = 0; XPathCollection queries = new XPathCollection(); queries.Add(new XPathExpression(xpathToUpdate)); //ValueMutator xpathMatcher = new ValueMutator(this.XPathCallBack); //Get resulting stream into response xml xDocOutput.Load(new XPathMutatorStream(memstream, queries, delegate(int matchIdx, XPathExpression expr, string origValue, ref string finalValue) { finalValue = newValue; })); //System.Diagnostics.Trace.WriteLine("Trace: " + memstream.Length.ToString()); } xDocOutput.Save(outputFileName); </code></pre> <p>The resulting output of this code is the file "Output.xml". Contained within the output document "Output.xml" is the following output:</p> <pre><code>&lt;ns0:TestXML xmlns:ns0="http://Test.Schemas" &gt; &lt;ns0:NodeA&gt; &lt;ns0:NodeB&gt; &lt;ns0:alpha Id="1" Value="Apple" Type="" &gt;fruit&lt;/ns0:alpha&gt; &lt;ns0:alpha Id="2" Value="Banana" Type="" &gt;fruit&lt;/ns0:alpha&gt; &lt;ns0:alpha Id="3" Value="Child" Type="" &gt;fruit&lt;/ns0:alpha&gt; &lt;ns0:alpha Id="4" Value="Duck" Type="" &gt;fruit&lt;/ns0:alpha&gt; &lt;/ns0:NodeB&gt; &lt;/ns0:NodeA&gt; &lt;/ns0:TestXML&gt; </code></pre> <p>As you will notice the "alpha" element's text value is updated incorrectly. The desired result is to update all attributes named "Type" with the value "Fruit". What is going wrong and how is this problem solved?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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