I am aware that this question has been asked multiple times on this site, however none of the previous answers have worked for me.
I have a String as XML like <A><B/><C></C></A>
When I use the pretty print converters I get:
<A>
<B/>
<C/>
</A>
I want to stop this and get the XML as it was. Like:
<A>
<B/>
<C></C>
</A>
I want an indent=2. Kindly help.
As mentioned in the comment section, for empty XML element tag both
<B></B>
and
<B/>
are equivalent.
I think you should try negotiate with your tester to save you the trouble as this sort of "fix" is deem as unnecessary. I would say your XML code is working as expected.
Try pointing your tester to the W3C XML specification.
See:
https://www.w3.org/TR/REC-xml/#NT-EmptyElemTag
Quote from the link above:
Examples of empty elements:
<IMG align="left"
src="http://www.w3.org/Icons/WWW/w3c_home" />
<br></br>
<br/>
Related
Actually I'm using summernote https://summernote.org/ plugin to style the text and saved it into database. It gives the string as <b style='color:#CCC'>Test</b>.
In normal text cases i'm using th:utext attribute. But i doesn't make this available for th:title. How to do this in thymeleaf ? Thanks in advance
In first scenario, i want to show it as text, So i used this implementation <span th:utext="${text}"></span> and this is working as expected
In second scenario, i want to show it as title for other tag like
<a th:title="${text}">Some other text </a> this gives title with tag as a string.Not applying styles to title. How can i get these title with text style provided by string
In both cases ${text} is <b style='color:#CCC'>Test</b>. How can i get unescaped text in title attribute.
If you are getting <b style='color:#CCC'>Test</b> string using model (like th:utext="${text}"), try like this:
From server: model.addAttribute("text", "<b style='color:#CCC'>Test</b>");
Html #1: <span th:utext="${text}"></span>
Html #2: <a th:title="${text}">Some other text </a>
I tried on my server and worked.
In CrafterCMS, in a content type, I have a field type RTE,
If I use the source option and write following code:
<p><span>Test</span></p>
<div class="item_icon"><i class="fa fa-location-arrow"></i></div>
after update it and be back the code is
<p><span>Test</span></p>
(last part was deleted)
Is this the expected behavior? can it be changed by configuration?
The Crafter team is working on an upgrade of TinyMCE in Crafter CMS 3.0, see here: https://github.com/craftercms/craftercms/issues/793
If you need a fix right away, you can try to use " ", or use a tag with: "display:none" for example: <span style="display:none">Something</span>
I'm trying to figure out a way to parse a html file with custom tags in the form:
[custom tag="id"]
Here's an example of a file I'm working with:
<p>This is an <em>amazing</em> example. </p>
<p>Such amazement, <span>many wow.</span> </p>
<p>Oh look, a wild [custom tag="amaze"] appears.</p>
We need maor embeds <a href="http://youtu.be/F5nLu232KRo"> bro
What I would like (in an ideal world) is to get back is a list of elements):
List foundElements = [text, custom tag, text, link, text]
Where the element in the above list contains:
Text:
<p>This is an <em>amazing</em> example. </p>
<p>Such amazement, <span>many wow.</span> </p>
<p>Oh look, a wild [custom tag="amaze"] appears.</p>
We need maor embeds
Custom tag:
[custom tag="amaze"]
Link:
<a href="http://youtu.be/F5nLu232KRo">
Text:
appears.</p>We need maor embeds
What I've tried:
Jsoup
Jsoup is great, it works perfectly for HTML. The issue is I can't define custom tags with opening "[" and closing "]". Correct me if I'm wrong?
Jericho
Again like Jsoup, Jericho works great..except for defining custom tags. You're required to use "<".
Java Regex
This is the option I really don't want to go for. It's not reliable and there's a lot of string manipulation that is brittle, especially when you're matching against a lot of regexes.
Last but not least, I'm looking for a performance orientated solution as this is done on an Android client.
All suggestions welcome!
Im trying to parse an XML using android. My problem is that the XML is in a strange format. The entirety of the data I'm trying to parse is located inside one element.
Here is an example:
<a name="3"></a>
<div class="series_alpha">
<h2 class="series_alpha">3</h2>
<ul class="series_alpha"><li>3 Banme no Kareshi<span class="mangacompleted">[Completed]</span></li>
<li>3 Gatsu no Lion</li>
<li>337 Byooshi</li>
<li>360 Degrees Material</li>
<li>37 Degrees Kiss<span class="mangacompleted">[Completed]</span></li>
<li>3x3 Eyes</li>
</ul>
<div class="clear"></div>
</div>
The XML is a piece of the source from this webpage. The data I'm trying to retrieve is found in the <li> tag, specifically the link reference and Manga name. But I dont know how I would separate the link from the title.
After looking it up I found the information inside the tags is known as an "attribute" (I'm a noob i know) and with some google searches found the attributes.getvalue("name of attribute here") method is what I was looking for.
source: XML Parsing to get Attribute Value
I'm trying to parse some HTML using XPath in Java. Consider this HTML:
<td class="postbody">
<img src="...""><br />
<br />
<b>What is Blah?</b><br />
<br />
Blah blah blah
<br />
Note that "What Is Blah" is helpfully contained within a b tag and is therefore easily parseable. But "Blah blah blah" is out in the open, and so I can only pick it up by calling text() on its parent node.
Thing is, I need to go through this in sequence, putting the img down, then the bolded text, then the body text. It's important it ends up in order (it needn't be processed in order, if you can suggest a way that takes two passes).
So are there any suggestions for how, if I've got the above contained within a Java XPath node, I can go through it in turn and get what I need?
I think an SAX based parser would be a better tool for this problem. It's event based so you can parse your XML document in order.
But it's an XML parser so you'll need to have a valid XML document. I never used JTidy but it's a java port of the HTML Tidy, so hopefully it can help you to transform your (invalid) HTML documents to a valid XML.
Use this XPath expression evaluated with the parent of the provided XML fragment as the context node:
node()
This selects every node - child of the context node -- every element -child, every text-node-child, every comment-child and every PI (processing instruction) - child.
In case you want to exclude comments and PIs, use:
node()[not(self::comment() or self::processing-instruction)]
In case that in addition to this you don't want to select the whitespace-only-text-nodes, use:
node()
[not(self::comment() or self::processing-instruction)]
[not(self::text()[string-length() = 0])]