Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to modify DocumentElement.Prefix in XmlDocument
    primarykey
    data
    text
    <p>I have some sets of xml in which I have to add namespace prefix on nodes which doesn't have any prefix.</p> <p>I have written a code which works for all nodes other than root element.</p> <p>Please point me to the thing which I can do change the root element prefix as well.</p> <pre><code> private void ReplaceFile(string xmlfile) { XmlDocument doc = new XmlDocument(); doc.Load(xmlfile); var a = doc.CreateAttribute("xmlns:mailxml12tm"); a.Value = "http://idealliance.org/Specs/mailxml12.0a/mailxml_tm"; doc.DocumentElement.Attributes.Append(a); doc.DocumentElement.Prefix = "mailxml12tm"; //foreach (XmlNode item in doc.SelectNodes("//*").Cast&lt;XmlNode&gt;().Where(item =&gt; item.Prefix.Length == 0)) //{ // item.Prefix = "mailxml12tm"; //} doc.Save(xmlfile); } </code></pre> <p>The xml file:</p> <pre><code>&lt;DeliveryApptCreateRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" p3:ApptType="Pallet" p3:PickupOrDelivery="Delivery" p3:ShipperApptRequestID="4490B0C07355" p3:SchedulerCRID="6498874" xmlns:p3="http://idealliance.org/Specs/mailxml12.0a/mailxml_defs"&gt; &lt;SubmitterTrackingID xmlns="http://idealliance.org/Specs/mailxml12.0a/mailxml_tm"&gt;2CAD3FBC71B1E1517021&lt;/SubmitterTrackingID&gt; &lt;DestinationEntry xmlns="http://idealliance.org/Specs/mailxml12.0a/mailxml_tm"&gt;No&lt;/DestinationEntry&gt; &lt;OneTimeAppt xmlns="http://idealliance.org/Specs/mailxml12.0a/mailxml_tm"&gt; &lt;PreferredAppt&gt;2012-07-01T09:00:00Z&lt;/PreferredAppt&gt; &lt;/OneTimeAppt&gt; &lt;/DeliveryApptCreateRequest&gt; </code></pre>
    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.
 

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