我的 XML 文件:
<?xml version="1.0"?>
<root>
<msg>
<MessageError>
<BookingID>123</BookingID>
<Error>Invalid patient name</Error>
<Error>PATIENT NOT FOUND</Error>
<Message>Incoming MESSAGE DATA 1</Message>
</MessageError>
<MessageError>
<BookingID>456</BookingID>
<Error>Undefined patient account number.</Error>
<Error>Undefined Account Number</Error>
<Message>Incoming MESSAGE DATA 2</Message>
</MessageError>
<MessageError>
<BookingID>789</BookingID>
<Error>DOB invalid</Error>
<Message>Incoming MESSAGE DATA 3</Message>
</MessageError>
</msg>
</root>
我的 tcl 脚本:
set dom [dom parse $msg]
set root [$dom documentElement]
set MessageError [$root selectNodes "/root/msg/MessageError" ]
foreach node $MessageError {
set Error [$root selectNodes {/root/msg/MessageError/Error} ]
#set bookingid [$MessageError text]
#echo "BookingIDXML - $bookingid"
#set message [$MessageError text]
#echo "MessageXML - $message"
foreach errornode $Error {
set error [$errornode text]
echo "ErrorXML - $error"
}
}
我的输出:
ErrorXML - Invalid patient name
ErrorXML - PATIENT NOT FOUND
ErrorXML - Undefined patient account number.
ErrorXML - Undefined Account Number
ErrorXML - DOB invalid
ErrorXML - Invalid patient name
ErrorXML - PATIENT NOT FOUND
ErrorXML - Undefined patient account number.
ErrorXML - Undefined Account Number
ErrorXML - DOB invalid
ErrorXML - Invalid patient name
ErrorXML - PATIENT NOT FOUND
ErrorXML - Undefined patient account number.
ErrorXML - Undefined Account Number
ErrorXML - DOB invalid
互联网上缺乏使用这个强大工具的文档。我如何获得输出?我的代码中带注释的“#”部分不起作用。
BookingIDXML - 123
ErrorXML - Invalid patient name
MessageXML - Incoming MESSAGE DATA 1
BookingIDXML - 123
ErrorXML - PATIENT NOT FOUND
MessageXML - Incoming MESSAGE DATA 1
BookingIDXML - 456
ErrorXML - Undefined patient account number.
MessageXML - Incoming MESSAGE DATA 2
BookingIDXML - 465
ErrorXML - Undefined Account Number
MessageXML - Incoming MESSAGE DATA 2
BookingIDXML - 789
ErrorXML - DOB invalid
MessageXML - Incoming MESSAGE DATA 3
提前致谢。