0

I have one XML, but it's not formatted. That's why I'm facing to do any transformation by XSLT. Extra < & > should be replaced with &gt;.

XML:

              <output>
                <line index="1">0a1,3</line>
                <line index="2">> ***************1# </line>
                <line index="3">> Building configuration... </line>
                <line index="4">>  </line>
                <line index="5">75c78</line>
                <line index="6">< enable secret 5 xxx</line>
                <line index="7">---</line>
                <line index="8">> enable secret 5 $1$okZh$nSIVWr7vNHAqk231PisjN0 </line>
                <line index="9">1986c1989</line>
                <line index="10">< snmp-server community  xxx</line>
                <line index="11">---</line>
                <line index="12">> snmp-server community sph1nkx5 v1default RO 5 </line>
                <line index="13">2043c2046</line>
                <line index="14">< tacacs-server key 7 xxx</line>
                <line index="15">---</line>
                <line index="16">> tacacs-server key 7 00070A160C5E190A002247 </line>
                <line index="17">2577a2581</line>
                <line index="18">> *************# </line>
              </output>

I want to convert it to:

         <output>
            <line index="1">0a1,3</line>
            <line index="2">&gt; ***************# </line>
            <line index="3">&gt; Building configuration... </line>
            <line index="4">&gt;  </line>
            <line index="5">75c78</line>
            <line index="6">&lt; enable secret 5 xxx</line>
            <line index="7">---</line>
            <line index="8">&gt; enable secret 5 $1$okZh$nSIVWr7vNHAqk231PisjN0 </line>
            <line index="9">1986c1989</line>
            <line index="10">&lt; snmp-server community  xxx</line>
            <line index="11">---</line>
            <line index="12">&gt; snmp-server community sph1nkx5 v1default RO 5 </line>
            <line index="13">2043c2046</line>
            <line index="14">&lt; tacacs-server key 7 xxx</line>
            <line index="15">---</line>
            <line index="16">&gt; tacacs-server key 7 00070A160C5E190A002247 </line>
            <line index="17">2577a2581</line>
            <line index="18">&gt; *************# </line>
          </output>

Perl & XSLT languages are okay to transform.

Biffen
  • 6,249
  • 6
  • 28
  • 36
Rudraprasad Pradhan
  • 181
  • 1
  • 1
  • 12
  • Is that a one-off job or a regular thing with varying input? – simbabque Mar 28 '18 at 12:02
  • 2
    If your XML is not well-formed then you won't be able to use XSLT on it, as that only accepts well-formed XML as an input. Well, potentially, you could use `unparsed-text`in XSLT 2.0, but you would then have to manipulate the document as a single string, not XML. Ideally you need to fix the issue at source, by correcting whatever process created the badly formed XML in the first place. – Tim C Mar 28 '18 at 12:32
  • 2
    This is why the XML spec says 'errors are fatal'. Because forward-fixing XML is a nasty job. – Sobrique Mar 28 '18 at 12:33
  • @Sobrique , Is there any way to make the XML valid using Perl? – Rudraprasad Pradhan Mar 29 '18 at 07:35
  • 1
    No. Even the XML spec says 'don't try to fix XML'. The problem is with the thing generating the XML, and you should take it up with them. Look at how it works with HTML - broken HTML is often handled by browsers, but it's done so badly and inconsistently. The whole point of XML is that there isn't any "interpretation" because it's a data transfer format. – Sobrique Mar 29 '18 at 08:54

0 Answers0