有谁知道通过使用XSD工具生成的类来探索反序列化的XML文件(而不是XPATH)有什么优点(内存/速度)?
我想说的好处是,您将获得一个更易于使用的强类型类,并且如果文件中的XML数据对于创建对象无效,则该类的构造函数也会引发异常,因此您将获得一个免费进行最少的数据验证。
如果您不想编写样板代码,并且在执行过程中需要检查XML的任何值,那么XSD.exe生成的类不会出错。
The two are very different; but XmlSerializer
will always deserialize entire objects; with XPath you can pick and choose. I'd use XmlSerializer
personally, though - harder to get wrong.
XPath, however, is a complex beast that depends on the back-end. For example, XmlDocument
(mutable) will behave differently to XPathDocument
(read-only, optimized for query).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.