开发者

How to get embbed XML from XML

开发者 https://www.devze.com 2023-02-22 01:36 出处:网络
I have a little problem, during sending request to serwer I\'m getting xml with embedded xml in it. Application works on Android 2.1 so I can not just use getTextContent() to get value, so I\'m using

I have a little problem, during sending request to serwer I'm getting xml with embedded xml in it. Application works on Android 2.1 so I can not just use getTextContent() to get value, so I'm using Node.getFirstChild().getNodeValue(); and for standard node with text it works fine but for node with embedded xml in it, it isn't. Does someone have any advice or had the sa开发者_如何学Cme problem? How to solve it.

BTW: When I checked type of node all of the are 1 so it means ELEMENT_NODE.


What exactly are you receiving from server? Something like;

<?xml version="1.0"?>
<embedded-xml>
  <?xml version="1.0"?>
  <data/>
</embedded-xml>

Or;

<?xml version="1.0"?>
<embedded-xml>
  <data/>
</embedded-xml>

In latter case you can simply retrieve data -node (not value), there's no need to parse it separately, while first case isn't exactly valid afaik.


You can't embed an arbitrary XML document in an XML document because XML documents can include sequences which are illegal with CDATA sections that are required to embed XML in the first place.

If the task is being able to embed, then extract, an arbitrary XML document, you have to encode the XML document, then embed it in a CDATA section. The reason is that the closing tag for CDATA is "]]>" and if the (arbitrary) embedded document contains a CDATA section, the "]]>" tag for that documents CDATA section will close the CDATA section in the parent.

In my experience, the best approach to embedding XML inside of XML is to compress (because Base64 encoding is going to blow it up ...) then Base64 encode. The reason I've taken this approach is because it is fool-proof and the two transforms (some kind of compressor and base64 en/de-coding) are widely available.

0

精彩评论

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

关注公众号