Hi I am currently having a problem with parsing an Xml string without any namespace, and added to an existing XElement with a namespace.
my code:
XElement elem = root.Element(xs + "methodCall");
if (elem != null)
{
XElement e = XElement.Parse(this.MethodCallXML);
elem.Add(e);
}
the result:
<methodCall>
<methodCall service="activity" method="activityDeleteComment" xmlns="">
<espSessionState>espSessionState1</espSessionState>
<traceFlowCode>true</traceFlowCode>
<params>
<commentID>http://uri1</commentID>
<isPermanentDelete>false</isPermanentDelete>
</params>
</methodCall>
</methodCall>
my problem is the xmlns="" I cannot figure out how to create the node using a parse method and give it a default namespace to use.
Is there any way of doing this?
Ok I figured out how to add the namespace to the new XElement and all descendants
foreach (XElement ce in e.DescendantsAndSelf())
ce.Name = xs + ce.Name.LocalName;
So far this solves my problem but if anyone can see a potential flaw or an easier way of doing this please let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With