Joao Scoob

Joao Scoob

  • NA
  • 18
  • 3k

XElement Displaying Child Node of parent if parent Empty

Nov 25 2018 5:16 AM
Hello guys is there any way that i can force in the final output to Display the Empty ChildNodes of the parent Node. The thing is since all the Child nodes of the parent node are Empty i am getting this output (this is just a segment of my XML):
 
<fpc::Header>
<fpc:Data>?fpc:Data>
 
and i want to be displayed like this through all the nodes where this happens:
 
<fpc:Header>
<fpc:Data>
<fpc:Id>?fpc:Id>
<fpc:Access>?</fpc:Access>
<fpc:Password>?</fpc:Password>
>
 
and this is the code:
 
foreach (XElement child in body.DescendantNodes().OfType().ToList())
{
child.Name = nsCsdb.GetName(child.Name.LocalName);
if (String.IsNullOrWhiteSpace(child.Value) || child.IsEmpty)
child.ReplaceWith(new XElement(child.Name, "?"));
}
 
so how can i enforce this to generate my soap Envelope as desired?
PS: ahh i am replacing self-closing tags to the normal start and end tag that's why the creation of the new XElement

Answers (1)