Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the namespace during a parse

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?

like image 686
Kezza Avatar asked Jun 20 '12 12:06

Kezza


Video Answer


1 Answers

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.

like image 52
Kezza Avatar answered Sep 16 '22 23:09

Kezza