英文:
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; Meghan </italic></bold>Ils quittent l'Angleterre à cause de William !</text>
<text><bold>INTERVIEW EXCLUSIVE </bold>L'émission de TF1 truquée ? Un danseur balance</text>
<text><bold>SCOOP <italic>Camille Combal </italic></bold>Et maintenant le bébé ! Deux mois à peine après son mariage, l'animateur star de TF1 est prêt à agrandir la famille avec Marie !</text>
<text><bold><italic>Jenifer </italic></bold>Visé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 :
<section><text><bold><italic>Iris Mittenaere </italic></bold>Son nouveau mec est une bombe !</text><text><bold><italic>Harry &amp; Meghan </italic></bold>Ils quittent l'Angleterre à cause de William !</text><text><bold>INTERVIEW EXCLUSIVE </bold>L'émission de TF1 truquée ? Un danseur balance</text><text><bold>SCOOP <italic>Camille Combal </italic></bold>Et maintenant le bébé ! Deux mois à peine après son mariage, l'animateur star de TF1 est prêt à agrandir la famille avec Marie !</text><text><bold><italic>Jenifer </italic></bold>Visée par un incendie criminel!</text></section>
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 <bold><italic>
tag.
Does anyone know how can i do this ?
答案1
得分: 0
我找到了一种处理方法,我认为不太干净,但我想不出更好的方法。我所做的是将xml标记替换为html标记:
text = text.replace("<article>","<body><article>")
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("<article>","<body><article>")
text = text.replace("bold", "b")
text = text.replace("italic", "i")
text = text.replace("text", "p")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论