check XML syntax with xmllint

前端 未结 3 2048
没有蜡笔的小新
没有蜡笔的小新 2021-02-03 17:43

I am having a problem with some XML print files where the source system omits to convert some characters to their XML syntax equivalent (e.g. & is not converted to &am

相关标签:
3条回答
  • 2021-02-03 18:08

    If you just need to check validity(correctness) of any xml document using xmllint, here is one more way.

    if xmllint --noout /tmp/test.xml > /dev/null 2>&1;
    then
        echo "correct"
    else
        echo "incorrect"
    fi
    
    0 讨论(0)
  • 2021-02-03 18:11
    xmllint --noout your_test_file.xml
    

    Check for return code of this command. See documentation. Value of 1 is returned when basic parsing errors are met. E.g.:

    echo $?
    
    0 讨论(0)
  • 2021-02-03 18:15
    xmllint --valid --encode utf-8 TEST.xml
    

    will validate and output TEST.xml in utf-8

    cat TEST.xml
    

    <xml version="1.0" encoding="utf-8"?>

    <!DOCTYPE JM SYSTEM "mydtd">

    <JM> . . . </JM>

    0 讨论(0)
提交回复
热议问题