Kotlin从XML到带样式的HTML

huangapple go评论85阅读模式
英文:

Kotlin from xml to html with style

问题

I have an XML file with some style:

<section>
    <text><bold><italic>Iris Mittenaere </italic></bold>Son nouveau mec est une bombe !</text>
    <text><bold><italic>Harry &amp;amp; Meghan </italic></bold>Ils quittent l&#39;Angleterre &#224; cause de William !</text>
    <text><bold>INTERVIEW EXCLUSIVE </bold>L&#39;&#233;mission de TF1 truqu&#233;e ? Un danseur balance</text>
    <text><bold>SCOOP <italic>Camille Combal </italic></bold>Et maintenant le b&#233;b&#233; ! Deux mois &#224; peine apr&#232;s son mariage, l&#39;animateur star de TF1 est pr&#234;t &#224; agrandir la famille avec Marie !</text>
    <text><bold><italic>Jenifer </italic></bold>Vis&#233;e par un incendie criminel!</text>
</section>

I use DOM as suggested here: https://www.baeldung.com/java-convert-xml-to-html to get the header and everything before the section and convert it to HTML; it works fine. My problem is that I can only get tags one by one. It works perfectly for the header, but here I have multiple text tags, so I only get the first one.

With Jackson XML, found here: https://www.baeldung.com/jackson-xml-serialization-and-deserialization, I managed to get multiple lines for text, but I can't get the style, meaning I can't retrieve the <bold><italic> tag.

Does anyone know how I can do this?

英文:

i have an xml file with some style :

&lt;section&gt;&lt;text&gt;&lt;bold&gt;&lt;italic&gt;Iris Mittenaere &lt;/italic&gt;&lt;/bold&gt;Son nouveau mec est une bombe !&lt;/text&gt;&lt;text&gt;&lt;bold&gt;&lt;italic&gt;Harry &amp;amp; Meghan &lt;/italic&gt;&lt;/bold&gt;Ils quittent l&#39;Angleterre &#224; cause de William !&lt;/text&gt;&lt;text&gt;&lt;bold&gt;INTERVIEW EXCLUSIVE &lt;/bold&gt;L&#39;&#233;mission de TF1 truqu&#233;e ? Un danseur balance&lt;/text&gt;&lt;text&gt;&lt;bold&gt;SCOOP &lt;italic&gt;Camille Combal &lt;/italic&gt;&lt;/bold&gt;Et maintenant le b&#233;b&#233; ! Deux mois &#224; peine apr&#232;s son mariage, l&#39;animateur star de TF1 est pr&#234;t &#224; agrandir la famille avec Marie !&lt;/text&gt;&lt;text&gt;&lt;bold&gt;&lt;italic&gt;Jenifer &lt;/italic&gt;&lt;/bold&gt;Vis&#233;e par un incendie criminel!&lt;/text&gt;&lt;/section&gt;

I use dom as sugested here : https://www.baeldung.com/java-convert-xml-to-html , to get the header and everything before the section and convert it to html, it s work fine. My probleme is that i can only get tag one by one, it s work perfect of the header but here i got multiple tag text so i only get the first one.

With jaksonxml found here : https://www.baeldung.com/jackson-xml-serialization-and-deserialization , i managed to get multiple line for text but i can't get the style meaning i can't reteive &lt;bold&gt;&lt;italic&gt; tag.

Does anyone know how can i do this ?

答案1

得分: 0

我找到了一种处理方法,我认为不太干净,但我想不出更好的方法。我所做的是将xml标记替换为html标记:

text = text.replace("&lt;article&gt;","&lt;body&gt;&lt;article&gt;")
text = text.replace("bold", "b")
text = text.replace("italic", "i")
text = text.replace("text", "p")
英文:

I found out a way to deal with it, i think it's not clean but i couldn't come up with anything better. What i did is that i replaced xml tag with html tag :

text = text.replace(&quot;&lt;article&gt;&quot;,&quot;&lt;body&gt;&lt;article&gt;&quot;)
        text = text.replace(&quot;bold&quot;, &quot;b&quot;)
        text = text.replace(&quot;italic&quot;, &quot;i&quot;)
        text = text.replace(&quot;text&quot;, &quot;p&quot;)

huangapple
  • 本文由 发表于 2020年7月22日 22:18:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63036397.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定