从xml文件中删除所有无效字符

时间:2019-03-28 15:16:56

标签: regex xml perl xmllint

我有一个xml文件,其中有错误,无效。

我如何(使用linux命令行实用程序或perl oneliner)从xml文件中删除所有无效字符?

我不介意数据丢失,我只需要删除这些无效字符

我从重复的问题中尝试了xmllint和xmlstarlet,但是没有运气。

xmlstarlet fo -o -R -H -D bad.xml 2> / dev / null

按照我得到的报告错误:

invalid_chars.xml:446669: parser error : Char 0xDD2F out of allowed range
            <elementA>Űᣣݫ존ᠴﵠ̝뫯���</elementA>
                                             ^
invalid_chars.xml:446669: parser error : PCDATA invalid Char value 56623
            <elementA>Űᣣݫ존ᠴﵠ̝뫯���</elementA>
                                             ^
invalid_chars.xml:446670: parser error : Char 0xD860 out of allowed range
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                         ^
invalid_chars.xml:446670: parser error : PCDATA invalid Char value 55392
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                         ^
invalid_chars.xml:446670: parser error : Char 0xD860 out of allowed range
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                                           ^
invalid_chars.xml:446670: parser error : PCDATA invalid Char value 55392
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                                           ^
invalid_chars.xml:446699: parser error : Char 0xDBF5 out of allowed range
            <elementA>Ϡ굱ߡﲠ���</elementA>
                                  ^
invalid_chars.xml:446699: parser error : PCDATA invalid Char value 56309
            <elementA>Ϡ굱ߡﲠ���</elementA>
                                  ^
invalid_chars.xml:446700: parser error : Char 0xD975 out of allowed range
            <elementE>륩䟠㩡 筠 ���존骞  佭 ᬧ, ᭜ꡩ ᰯ嫥 존骼 紡 
                                         ^
invalid_chars.xml:446700: parser error : PCDATA invalid Char value 55669
            <elementE>륩䟠㩡 筠 ���존骞  佭 ᬧ, ᭜ꡩ ᰯ嫥 존骼 紡 
                                         ^
invalid_chars.xml:446703: parser error : Char 0xDA64 out of allowed range
            <elementA>hޭ៣ʯ���ܱ矤 1992</elementA>
                                ^
invalid_chars.xml:446703: parser error : PCDATA invalid Char value 55908
            <elementA>hޭ៣ʯ���ܱ矤 1992</elementA>
                                ^
invalid_chars.xml:446730: parser error : Char 0xDD1D out of allowed range
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                ^
invalid_chars.xml:446730: parser error : PCDATA invalid Char value 56605
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                ^
invalid_chars.xml:446730: parser error : Char 0xDBE9 out of allowed range
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                   ^
invalid_chars.xml:446730: parser error : PCDATA invalid Char value 56297
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                   ^
invalid_chars.xml:446758: parser error : Char 0xD9F2 out of allowed range
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                        ^
invalid_chars.xml:446758: parser error : PCDATA invalid Char value 55794
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                        ^
invalid_chars.xml:446758: parser error : Char 0xD860 out of allowed range
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                                           ^
invalid_chars.xml:446758: parser error : PCDATA invalid Char value 55392
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                                           ^
invalid_chars.xml:446795: parser error : Char 0xDD2F out of allowed range
            <elementA>Űᣣݫ존ᠴﵠ̝뫯���</elementA>
                                             ^
invalid_chars.xml:446795: parser error : PCDATA invalid Char value 56623
            <elementA>Űᣣݫ존ᠴﵠ̝뫯���</elementA>
                                             ^
invalid_chars.xml:446796: parser error : Char 0xD860 out of allowed range
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                         ^
invalid_chars.xml:446796: parser error : PCDATA invalid Char value 55392
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                         ^
invalid_chars.xml:446796: parser error : Char 0xD860 out of allowed range
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                                           ^
invalid_chars.xml:446796: parser error : PCDATA invalid Char value 55392
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                                           ^
invalid_chars.xml:446825: parser error : Char 0xDBF5 out of allowed range
            <elementA>Ϡ굱ߡﲠ���</elementA>
                                  ^
invalid_chars.xml:446825: parser error : PCDATA invalid Char value 56309
            <elementA>Ϡ굱ߡﲠ���</elementA>
                                  ^
invalid_chars.xml:446826: parser error : Char 0xD975 out of allowed range
            <elementE>륩䟠㩡 筠 ���존骞  佭 ᬧ, ᭜ꡩ ᰯ嫥 존骼 紡 
                                         ^
invalid_chars.xml:446826: parser error : PCDATA invalid Char value 55669
            <elementE>륩䟠㩡 筠 ���존骞  佭 ᬧ, ᭜ꡩ ᰯ嫥 존骼 紡 
                                         ^
invalid_chars.xml:446829: parser error : Char 0xDA64 out of allowed range
            <elementA>hޭ៣ʯ���ܱ矤 1992</elementA>
                                ^
invalid_chars.xml:446829: parser error : PCDATA invalid Char value 55908
            <elementA>hޭ៣ʯ���ܱ矤 1992</elementA>
                                ^
invalid_chars.xml:446856: parser error : Char 0xDD1D out of allowed range
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                ^
invalid_chars.xml:446856: parser error : PCDATA invalid Char value 56605
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                ^
invalid_chars.xml:446856: parser error : Char 0xDBE9 out of allowed range
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                   ^
invalid_chars.xml:446856: parser error : PCDATA invalid Char value 56297
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                   ^
invalid_chars.xml:446884: parser error : Char 0xD9F2 out of allowed range
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                        ^
invalid_chars.xml:446884: parser error : PCDATA invalid Char value 55794
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                        ^
invalid_chars.xml:446884: parser error : Char 0xD860 out of allowed range
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                                           ^
invalid_chars.xml:446884: parser error : PCDATA invalid Char value 55392
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                                           ^
invalid_chars.xml:446921: parser error : Char 0xDD2F out of allowed range
            <elementA>Űᣣݫ존ᠴﵠ̝뫯���</elementA>
                                             ^
invalid_chars.xml:446921: parser error : PCDATA invalid Char value 56623
            <elementA>Űᣣݫ존ᠴﵠ̝뫯���</elementA>
                                             ^
invalid_chars.xml:446922: parser error : Char 0xD860 out of allowed range
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                         ^
invalid_chars.xml:446922: parser error : PCDATA invalid Char value 55392
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                         ^
invalid_chars.xml:446922: parser error : Char 0xD860 out of allowed range
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                                           ^
invalid_chars.xml:446922: parser error : PCDATA invalid Char value 55392
            <elementE>Я鼠 尜 㣥묡 ���䩡띮崥  㩡 ���ⱥߴ堤 ﵫ婜 </element
                                                           ^
invalid_chars.xml:446951: parser error : Char 0xDBF5 out of allowed range
            <elementA>Ϡ굱ߡﲠ���</elementA>
                                  ^
invalid_chars.xml:446951: parser error : PCDATA invalid Char value 56309
            <elementA>Ϡ굱ߡﲠ���</elementA>
                                  ^
invalid_chars.xml:446952: parser error : Char 0xD975 out of allowed range
            <elementE>륩䟠㩡 筠 ���존骞  佭 ᬧ, ᭜ꡩ ᰯ嫥 존骼 紡 
                                         ^
invalid_chars.xml:446952: parser error : PCDATA invalid Char value 55669
            <elementE>륩䟠㩡 筠 ���존骞  佭 ᬧ, ᭜ꡩ ᰯ嫥 존骼 紡 
                                         ^
invalid_chars.xml:446955: parser error : Char 0xDA64 out of allowed range
            <elementA>hޭ៣ʯ���ܱ矤 1992</elementA>
                                ^
invalid_chars.xml:446955: parser error : PCDATA invalid Char value 55908
            <elementA>hޭ៣ʯ���ܱ矤 1992</elementA>
                                ^
invalid_chars.xml:446982: parser error : Char 0xDD1D out of allowed range
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                ^
invalid_chars.xml:446982: parser error : PCDATA invalid Char value 56605
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                ^
invalid_chars.xml:446982: parser error : Char 0xDBE9 out of allowed range
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                   ^
invalid_chars.xml:446982: parser error : PCDATA invalid Char value 56297
            <elementA>hޭ៣̯������ ʡ鱯 ߟd2005</elementA>
                                   ^
invalid_chars.xml:447010: parser error : Char 0xD9F2 out of allowed range
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                        ^
invalid_chars.xml:447010: parser error : PCDATA invalid Char value 55794
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                        ^
invalid_chars.xml:447010: parser error : Char 0xD860 out of allowed range
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                                           ^
invalid_chars.xml:447010: parser error : PCDATA invalid Char value 55392
            <elementA>ʡ맬ݱᠴ嬰 嫩 ܟe屟  粠 ݷ��� ꡩ 粠 ᭜㪧 ���ꜭ婲  
                                                                           ^
invalid_chars.xml:512490: parser error : Char 0xD863 out of allowed range
            <elementA>֡ߤﲟfЫܴퟧ婳 ᣹㞭쥴᳧ܶ-멡 С���龴 粠 ļ꯲, 尩 읫
                                                                ^
invalid_chars.xml:512490: parser error : PCDATA invalid Char value 55395
            <elementA>֡ߤﲟfЫܴퟧ婳 ᣹㞭쥴᳧ܶ-멡 С���龴 粠 ļ꯲, 尩 읫
                                                                ^
invalid_chars.xml:512595: parser error : Char 0xDBF2 out of allowed range
            <elementA>ʱߴퟦЫܴ���</elementA>
                                   ^
invalid_chars.xml:512595: parser error : PCDATA invalid Char value 56306
            <elementA>ʱߴퟦЫܴ���</elementA>
                                   ^
invalid_chars.xml:512628: parser error : Char 0xDBF6 out of allowed range
            <elementA>Υ������ ū맭骜 </elementA>
                          ^
invalid_chars.xml:512628: parser error : PCDATA invalid Char value 56310
            <elementA>Υ������ ū맭骜 </elementA>
                          ^
invalid_chars.xml:512628: parser error : Char 0xDD2F out of allowed range
            <elementA>Υ������ ū맭骜 </elementA>
                             ^
invalid_chars.xml:512628: parser error : PCDATA invalid Char value 56623
            <elementA>Υ������ ū맭骜 </elementA>

样本记录:

<RECORD ID="1">
        <RECNO>10962</RECNO>
        <RECSTATUS>c</RECSTATUS>
        <RECTYPE>a</RECTYPE>
        <BIBLIOGRAPHICLEV>m</BIBLIOGRAPHICLEV>
        <HIERARCHICALLEV>|</HIERARCHICALLEV>
        <DATE>4/12/2000</DATE>
        <TIMEID>11/3/2003 7:31:41 μμ</TIMEID>
        <ATION>Űᣣݫ ᠴ</ATION>
        <SUBFIELD_2>001 </SUBFIELD_2>
        <SUBFIELD_A>Űᣣݫ존ᠴﵠ̝뫯���</SUBFIELD_A>
        <SUBFIELD_E>Я鼠尜㣥묡 ���䩡띮崥 㩡 ���ⱥߴ堤ﵫ婜</SUBFIELD_E>
        <SUBFIELD_F>ȼ乱ﲠʡ᭝⡲</SUBFIELD_F>
        <SUBFIELD_2>10  </SUBFIELD_2>
        <SUBFIELD_A>hޭ៣Сᦞ粟d1998</SUBFIELD_A>
        <SUBFIELD_2>15  </SUBFIELD_2>
        <SUBFIELD_A>157 .</SUBFIELD_A>
        <SUBFIELD_D>21 媮</SUBFIELD_D>
                </RECORD>

0 个答案:

没有答案