Replace line in generated XML

Replace line in generated XML

  
Hello Genius people,

I am generating XML file using RecordListtoXML control. After generating xml, I am replacing few values in XML using Replace() function.

My generated structure is:
<LIABILITY ID="1" VALUE="ABC">
</LIABILITY>
<LIABILITY ID="2" VALUE="XYZ">
</LIABILITY>
<LIABILITY ID="3" VALUE="JKL">
</LIABILITY>

After replacement:
I am replacing </LIABILITY> by empty space i.e. ""
and after that ">" by " />"

It's giving me result like this:
<LIABILITY ID="1" VALUE="ABC" />

<LIABILITY ID="2" VALUE="XYZ" />

<LIABILITY ID="3" VALUE="JKL" />

I want to remove this line between two nodes.
i.e. my result should be like this
<LIABILITY ID="1" VALUE="ABC" />
<LIABILITY ID="2" VALUE="XYZ" />
<LIABILITY ID="3" VALUE="JKL" />

Is there any way to replace that empty line?

Please advice.

Thanks,
Suraj Borade

Why do you want to do that?
it's the same?


Hi J,

Thanks for the reply.

I need to send this generated XML to another server. So I want to format my generated XML. I don't want space between two lines. I
I think if there is space between two lines, another server will not be able to parse this XML.


But why are you replacing the </Liability> tags at all?
Explicit closing tags and Self-Closing tags are the same in XML ...any xml parser needs to support them.
Did you actually had problems with it or are just assuming the server won't work?

We can explain how to do the replacements you want
..but you shouldn't need any of them...

Regards,
João Rosado
Hi Joao,

Thanks for quick reply.

I am replacing Explicit closing tag because client want to see it as Self-Closing. So I want to format my XML output.
Hi Joao,

Can you please tell how to replace the empty line?

We need it now and can't push it any more since client wants to see formatted XML file.

Thanks a lot.

-- Suraj B
Hi Suraj,

Have you tried the regular expressions helper functions? They should work for your scenario by replacing that exact closing tag with the closing tag characters you mentioned.

Regards,
Pedro
Thanks a lot Pedro.
Hi Pedro,

Sorry, I thought my issue was resolved but problem is still there.

I tried replacing result like this Regex_Replace(GeneratedXML,"\n","",True,True,True) but it is treating "\n" as a string. Can you please suggest how should I set value of new line character in this replace?

Thanks a lot.

-- Suraj B
Hello Suraj,

I'm not really sure about this, but "\n" doesn't seem to me a valid Regular Expression (Regex) for .NET

You are probably best served googling for Regex .NET syntax or in your specific case regex to replace html tags to which I found a few examples here and here. Probably these also need some tweaks.

Let me know how did it go, for you.