0

I have an XML file as shown below:

<headerRule name='modifyCType'
            headerName='Content-Type'
            action='manipulate'
            matchValue='($checkPT18.$chkPT18)&!$checkAnnexb.$chkAnnexb)'
            newValue='<'
            methods='INVITE'>
</headerRule>

While unmarshalling using JAXB, it says invalid character & on matchValue='($checkPT18.$chkPT18)&!$checkAnnexb.$chkAnnexb)' which I replaced with &amp and it is working now i.e. matchValue='($checkPT18.$chkPT18)&amp;!$checkAnnexb.$chkAnnexb)'.

However, there is another invalid character < on newValue='<' when I replace it with &lt it works fine however it replaces all '<' character with &lt including &ltheaderRule as shown below:

&lt;headerRule name='modifyCType'
            headerName='Content-Type'
            action='manipulate'
            matchValue='($checkPT18.$chkPT18)&amp;!$checkAnnexb.$chkAnnexb)'
            newValue='&lt;'
            methods='INVITE'>
&lt;/headerRule>

which I do not want. I want:

<headerRule name='modifyCType'
            headerName='Content-Type'
            action='manipulate'
            matchValue='($checkPT18.$chkPT18)&amp;!$checkAnnexb.$chkAnnexb)'
            newValue='&lt;'
            methods='INVITE'>
</headerRule>

How to replace < with &lt only for attribute value i.e. newValue using jaxb parsing?

Nitin
  • 53
  • 9
  • `newValue='<'` should work. – Stephen C Sep 17 '20 at 06:00
  • @StephenC it works, however, it replaces all < including – Nitin Sep 17 '20 at 06:01
  • How can we solve it using jaxb, during parsing – Nitin Sep 17 '20 at 06:02
  • Your question is really confusing. Please update the example to reflect your actual problem. (You have diagnosed and fixed the problems with the `<` and `&` characters by using character references. So show us the *fixed* XML and get rid of the irrelevant stuff about how you fixed that.) – Stephen C Sep 17 '20 at 06:06
  • @StephenC I have updated question, hope it helps you now – Nitin Sep 17 '20 at 06:11
  • Does this answer your question? [Escaping special character when generating an XML in Java](https://stackoverflow.com/questions/4301236/escaping-special-character-when-generating-an-xml-in-java) – Lakshan Sep 21 '20 at 04:38

0 Answers0