14

I have answered a potentially not well received question, so the question including my answer was deleted by the community (or even by the OP himself, I don't know). I went to my list of deleted answers to copy it for myself in order to put it in my own Wiki. I see the answer in the list, but I cannot view it (link for 10k+).

I know that only 10k+ users can see other users deleted questions, but I think that the system shouldn't prevent me from viewing my own answers.

5
  • to copy it for myself Here would be the link of the source of your answer: stackoverflow.com/revisions/… (I'm not 100% sure, but I think you can access it) Maybe you even can access the revisions of it: stackoverflow.com/posts/28585651/revisions
    – Rizier123
    Commented Feb 27, 2015 at 9:29
  • 1
    @Rizier123 : no a <10k user can access its deleted questions or answers, but not the answers he wrote on a deleted question he did not wrote Commented Feb 27, 2015 at 10:05
  • @Rizier123: FYI: I cannot see access the source ("view-source" link), but I can access the revision history ("revision" link). Commented Feb 27, 2015 at 10:43
  • @ᵺṓᵯᶏᵴ Ah okay, interesting, as I said I didn't know what you can access and what not :D Now I know it
    – Rizier123
    Commented Feb 27, 2015 at 10:44
  • @Rizier123: see also the follow-up at meta.stackoverflow.com/questions/287032/… Commented Feb 27, 2015 at 11:56

1 Answer 1

5

I had same problem some month ago. I both asked for it in meta and sent a mail to moderators.

The moderator answer was that the correct way was indeed to ask them for the answer text ... but it came several days after a 10k+ copied my deleted answer in meta.

So here is your answer :


Almost any content can be used as text of an element. Any XML library should provide a way to set the text of the element and by doing that, the library will escape all of the five special characters (>, <, &, " and '). There is no need for CDATA.

In your case, the library would escape the text to

<reference>A;&amp;94-230</reference>

which is perfectly fine XML. If the destination of the XML also uses a XML library, the library will convert the text back to

A;&94-230

There's not need to perform a validity before setting the text.

Edit

Setting the text

string_contains_CDATA-section-close_delimiter ]]>

on a tagelement will result in

<tag>string_contains_CDATA-section-close_delimiter ]]&gt;</tag>

which is again valid XML.

Edit 2

Find this unit test which uses JDom

@Test
public void XMLSpecialCharacterTest() throws Exception
{
    try
    {
        // Set up everything
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dombuilder= factory.newDocumentBuilder();
        InputStream is = new ByteArrayInputStream( "<reference/>".getBytes("UTF-8"));
        org.w3c.dom.Document w3cDocument = dombuilder.parse(is);
        DOMBuilder jdomBuilder = new DOMBuilder();
        Document jdomDocument = jdomBuilder.build(w3cDocument);
        Element rootElement = jdomDocument.getRootElement();

        // Do the actual tests
        rootElement.setText("A;&94-230");
        System.out.println(new XMLOutputter().outputString(jdomDocument));

        rootElement.setText("Some text with CDATA ]]>");
        System.out.println(new XMLOutputter().outputString(jdomDocument));
    } catch (ParserConfigurationException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
3
  • I am about accepting this answer. Do you think the fact that I cannot see access the source ("view-source" link), but I can access the revision history ("revision" link) is worth starting a new question? Or should I post this as an additional answere here? Commented Feb 27, 2015 at 10:48
  • @ᵺṓᵯᶏᵴ : do not post that as an answer as it would not be one ! IMHO, you should post it as a new question with a link to this one Commented Feb 27, 2015 at 11:31
  • Done, as feature request: meta.stackoverflow.com/questions/287032/… Commented Feb 27, 2015 at 11:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .