in reply to [Solved]:What regex changes are needed while creating xml

Does this look right?

<?xml version="1.0"?> <doc> <GI-eSTB-MIB-NPH> <eSTBUserSettingOutput> <0>INTEGER: hd1920x1080i(1)</0> </eSTBUserSettingOutput> <eSTBUserSetting43OverRide> <0>INTEGER: on480p(3)</0> </eSTBUserSetting43OverRide> </GI-eSTB-MIB-NPH> </doc>

If so:

/ ^(.*?):: ([^\s]+) \.([^\s]+)\s+= \s(.*) /x;

Two lines of input data isn't really reliable to craft a strong regex, so if the above code works, you'll just have to test it against a larger dataset.

-stevieb

Replies are listed 'Best First'.
Re^2: What regex changes are needed while creating xml
by Perl300 (Friar) on Jun 25, 2015 at 19:21 UTC
    Hi stevieb, That works and thank you for your help. Yes, I agree that just two lines are not enough for thorough testing, and so I tried to run it on the entire file that gets generated dynamically but got the following error:
    Code point \u0016 is not a valid character in XML at ./Call_to_snmpwal +k.pl line 32.

    This is line $xml->dataElement($subscript_name => $subscript_value);

    I am trying to see what else can I find. It seems like data related issue though as from error message it looks like: Some data was generated which is not considered as valid xml character.

    @toolid: Thank you for your help, but I was using $string1 in code at:

    $xml->startTag($string1);
      I searched for error: "Code point \u0016 is not a valid character in XML at ./Call_to_snmpwalk.pl line 32" It seems that this error is being generated due to control characters present in the text which are not allowed in xml. So I have two options:

      1) Remove these control characters from the file and then print: I have tried this using

      perl -pe's/\x08//g' <file1.xml >file1.xml

      But this gives error: Bad name after g' at <script_name>.pl line 13.

      2) To actually generate an xml (actual .xml file) from code and put the text that is converted in xml into this file and then read it. Do anyone have any suggestions on point 1 or 2?

        Never redirect both from and to the same file at the same time: the file will be clobbered. Instead use the -i option to edit in place. Don't forget the trailing semicolon either.

        perl -pi -e 's/\x08//g;' file1.xml

        It would be helpful if you could show a couple of the lines that are causing you this specific grief.

        -stevieb