I do not want to parse some tags in XML

This is currently going to be an XML sample I'm working on:

<smsq>
  <sms>
  <id>96</id>
  <to>03333560511</to>
  <msg>  danial says: hahaha <space> nothing.
  </msg>
  </sms>
</smsq>

Now note that the tag may contain other tags (which should not be parsed), and I had to make dtd for this. Dtd was something like this:

<!DOCTYPE smsq [
  <!ELEMENT sms (mID,to,msg,type)>
  <!ELEMENT mID (#PCDATA)>
  <!ELEMENT to (#PCDATA)>
  <!ELEMENT msg (CDATA)>
]>

But the problem is that the XML parser still goes in the tag and says that the tag should be closed by the tag. I just want to get the data as it is from XML, and I no longer want to parse the messages.

Help me solve the problem and tell me if this can be done using DTD.

Thank!

+3
source share
5 answers

Firstly, the xml sample is not really xml because the "space" tag is not closed.

-, , , "space", xml - , xml. /, CDATA.

- , xml, . XML - - - , , - .

!

+1

DTD, XML . XML , , ( AFAICT). , , .

<space> . </space> </space> <msg>, <space/>, , , , , , "<space>" , (.. &lt;space&gt;).

+4

DTD . DTD ( ).

, , XML-. . , , XML , .

, < XML- &lt;.

+3

XML , <tag></tag> <tag />.

, <space> , , &lt; &gt; < >:

&lt;space&gt;
+1

. , .

private static String getMessage(String msg){
    return msg.substring(msg.indexOf("<msg>")+5, msg.lastIndexOf("</msg>"));
}//method

, .

: - "msg" ,

0
source

Source: https://habr.com/ru/post/1761009/


All Articles