Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法从内容处理程序内部停止解析?还是抛出异常是唯一的方法?
请注意,我正在使用xml.sax.parseString。
Python 的 SAX 内容处理程序的完整 API 记录在这里:如您所见,信息流完全是单向的,解析器到处理程序 - 处理程序无法将信息提供回解析器(例如解析是否应该被终止)。
因此,正如您所猜测和评论者所证实的那样,“控制流异常”确实是实现这种“过早终止”的唯一方法。正如评论者所提到的,毕竟还不错。