开发者

Android: Get XML from SAX Element

Can I get a string of XML from a SAX Element class in Android? For example, in DOM parsing in .NET, we can get the OuterXml or InnerXml of a node. Unless I'm overlooking something, it seems that there is no way to do that either using SAX or DOM parsing in Android. Am I right about that (I hope not)?

Using SAX, we can do something like:

Element childElt = rootElt.getChild(CHILD_ELT_NAME);
if(childElt != null) {
 childElt.setEndTextElementListener(new EndTextElementListener() {
  @Override
  public void end(String body) {
   //Do something with the body string
  }
 });
}

That will allow us to get at the "value" of the child element. Is there anything similar开发者_运维问答 that will allow us to get at the XML representation of the element and its children?

Thank you.


If you are attempting to do operations that are tree structure sensitive, you should use DOM. What you appear to be trying to do would seem to fit that description, so I would suggest you use a DOM parser.

For a discussion of SAX v. Dom (Event vs. Tree) see: http://www.saxproject.org/event.html


With VTD-XML, you can get the token index and convert them to string for further processing, if simplicity is what you look for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜