In a loop, each time i need to parse a new xml and in xml i have to parse some specific nodes, if they has value then copy them to another file else keep going until the last xml, how to do it ?
在一个循环中,每次我需要解析一个新的xml并在xml中我必须解析一些特定的节点,如果它们有值,那么将它们复制到另一个文件,否则一直持续到最后一个xml,怎么做?
2 个解决方案
#1
1
The essence of Sax is that you don't own the flow of control: when you say "in a loop", you are hinting that you want the flow of control. With Sax, the parser calls you when it's ready to do so. If you want to be in control, try using a pull parser (Stax, for example Woodstox).
Sax的本质是你不拥有控制流:当你说“循环”时,你暗示你想要控制流。使用Sax,解析器在准备好时会调用它。如果你想控制,尝试使用拉解析器(Stax,例如Woodstox)。
#2
0
If all you want is to get the contents of specific nodes, I'd consider using XPath, it allows you to get a list of nodes matching your search criteria. That way you might be able to avoid using a SAX parser and creating your own content handler.
如果您只想获取特定节点的内容,我会考虑使用XPath,它允许您获取符合搜索条件的节点列表。这样您就可以避免使用SAX解析器并创建自己的内容处理程序。
#1
1
The essence of Sax is that you don't own the flow of control: when you say "in a loop", you are hinting that you want the flow of control. With Sax, the parser calls you when it's ready to do so. If you want to be in control, try using a pull parser (Stax, for example Woodstox).
Sax的本质是你不拥有控制流:当你说“循环”时,你暗示你想要控制流。使用Sax,解析器在准备好时会调用它。如果你想控制,尝试使用拉解析器(Stax,例如Woodstox)。
#2
0
If all you want is to get the contents of specific nodes, I'd consider using XPath, it allows you to get a list of nodes matching your search criteria. That way you might be able to avoid using a SAX parser and creating your own content handler.
如果您只想获取特定节点的内容,我会考虑使用XPath,它允许您获取符合搜索条件的节点列表。这样您就可以避免使用SAX解析器并创建自己的内容处理程序。