The issue in your case is related to the encoding mismatch between the XML file and the tool (xmlstarlet) processing it. Here's what's happening:
XML Declaration: Your test.xml file declares its encoding as UTF-16:
xml<?xml version="1.0" encoding="UTF-16"?>
However, the actual content of the file is likely not encoded in UTF-16. The file appears to be in a different encoding (possibly UTF-8 or ASCII), but the declaration explicitly states UTF-16.
xmlstarlet Behavior:
xmlstarlet reads the XML declaration and expects the file to be in UTF-16.xmlstarlet will fail to parse it, resulting in the error:
textparsing XML declaration: '?>' expected
If your file is not UTF-16 encoded (e.g., it's UTF-8 or ASCII), update the XML declaration to match the actual encoding:
xml<?xml version="1.0" encoding="UTF-8"?>
Then save the file as UTF-8.
If you want to keep the declaration as UTF-16, ensure the file is actually saved in UTF-16 encoding. You can do this using tools like:
iconv (Linux/macOS):
bashiconv -f UTF-8 -t UTF-16 test.xml > test_utf16.xml
xmlstarlet to Ignore EncodingIf you are sure the file is UTF-8 but misdeclared, you can preprocess it to remove the encoding attribute or use a tool like recode to fix it.
After fixing the encoding, run your command again:
bashcat test.xml | xmlstarlet sel -t -v '//node/@bounds'
If the file is correctly encoded, this should work without errors.
Vibe can make mistakes. Check answers. Learn more