How do I include &, <, > etc in XML attribute values

后端 未结 2 800
忘掉有多难
忘掉有多难 2020-11-30 12:13

I want to create an XML file which will be used to store the structure of a Java program. I am able to successfully parse the Java program and create the tags as required. T

2条回答
  •  失恋的感觉
    2020-11-30 12:57

    In XML attributes you must escape

    " with "
    < with <
    & with &
    

    if you wrap attribute values in double quotes ("), e.g.

    
    

    meaning tag MyTag with attribute attr with text If a - note: no need to use ' to escape ' character.

    If you wrap attribute values in single quotes (') then you should escape these characters:

    ' with '
    < with <
    & with &
    

    and you can write " as is. Escaping of > with > in attribute text is not required, e.g. is well-formed XML.

提交回复
热议问题