Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the method for registering new tags in XML and the possibility of saying "formatAsBlock" false or true #1428

Open
dcmarcelino opened this issue Sep 23, 2020 · 1 comment

Comments

@dcmarcelino
Copy link

dcmarcelino commented Sep 23, 2020

In our system, we created some xml tags to facilitate our understanding, but some we want in the parser, to be considered as inline, because we need the number of characters of the text faithful to what was written, because without this, I was adding formatting spaces

exemple:

<assessment-group id="2C93808974B5C5DA0174B73EB5712FBA"> 
            <label> 2. </label> 
            <highlight show-answer="true" id="2C93808974B5C5DA0174B73EB5712FBB"> 
                <question> 
                    <p id="2C93808974B5C5DA0174B73EB5712FBC">Underline the best word to complete each sentence below.</p> 
                </question> 
                <items> 
                    <item id="2C93808974B5C5DA0174B73EB5712FBD">He has <token type="underline" color="any">received</token> many gifts, <strong>but</strong> his wife <strong>has</strong> received <strong>no /</strong> <token type="underline" color="any">none</token></item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FBE">The <strong>bird</strong> hasn't drunk <token type="circle" color="any"><strong>any</strong></token> <strong> / some</strong> water today.</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FBF">Did you watch <strong>no / </strong> <token type="underline" color="any"> any </token> films last month?</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC0">I have <token type="underline" color="any"> some </token> <strong> / any</strong> news for you.</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC1">Steven is going to answer <token type="underline" color="any"> no </token> <strong>/ any</strong> e-mails tomorrow.</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC2">There is <token type="underline" color="any"> no </token> <strong>/ any</strong> reason to worry about Dan.</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC3">He has received many gifts, <strong>but</strong> his wife <strong>has</strong> received <strong>no /</strong> <token type="underline" color="any">none</token></item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC4">Would you care for <strong>any / </strong> <token type="underline" color="any"> some </token> finger food?</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC5">Bring <token type="underline" color="any"> some </token> <strong> / any</strong> recyclable material next class.</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC6">If you have <token type="underline" color="any"> any </token> <strong> / no</strong> suggestions, contact me.</item> 
                    <item id="2C93808974B5C5DA0174B73EB5712FC7">We seldom eat <strong>no / </strong> <token type="underline" color="any"> any </token> fattening food.</item> 
                </items> 
            </highlight> 
</assessment-group>

for now, we have created a way to do it, but it is not a good practice

static {
	try {
		String[] inlineTags = {"token", "item"};
		for(String tagName : inlineTags) {
			Tag tag = Tag.valueOf(tagName);
			Field field = Tag.class.getDeclaredField("formatAsBlock");
			field.setAccessible(true);
			field.set(tag, false);
			
			Method method = Tag.class.getDeclaredMethod("register", Tag.class);
			method.setAccessible(true);
			method.invoke(null, tag);				
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
@FhToday
Copy link

FhToday commented Apr 25, 2021

Hi! Which functions did you use to process this XML? I found that if I use Jsoup.parse, it will automatically register tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants