1e41f4b71Sopenharmony_ci# ArkTS Subsystem Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## cl.arkts.1 Behavior Changed for xml.XmlPullParser.parse in Parsing Entity Reference Events 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**Access Level** 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciPublic API 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**Reason for Change** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciWhen parsing an XML file, the **parse** interface identifies an entity reference event as a text event, and the parsed content is integrated into the text event. Consequently, the callback function specified in **tokenValueCallbackFunction** cannot obtain the parsing result of the entity reference event. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Change Impact** 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThis change is a non-compatible change. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciBefore change: The XML information of an entity reference event is parsed into a text event. You cannot perform operations on the entity reference event in the callback function or determine whether the entity reference event exists based on the XML parsing result. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciAfter change: In API version 12 or version, the XML information of an entity reference event is parsed as an entity reference event. You can perform operations on the entity reference event in the callback function or determine whether the entity reference event exists based on the XML parsing result. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Start API Level** 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciAPI version 12 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Change Since** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciOpenHarmony SDK 5.0.0.38 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Key API/Component Changes** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_cixml.XmlPullParser.parse 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Adaptation Guide** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciIf the XML file does not involve entity reference events, no adaptation is required. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciIf the XML file involves entity reference events, refer to the following example to learn the differences before and after the change. In the code snippet below, **strXml** stores the XML file to be parsed, and **func** is the callback function **tokenValueCallbackFunction**. Each event obtained upon a **parse** call triggers a callback, and the event type and XML parsing result are included in the callback. 38e41f4b71Sopenharmony_ci``` 39e41f4b71Sopenharmony_cilet strXml = '<?xml version="1.0" encoding="utf-8"?>\n' + 40e41f4b71Sopenharmony_ci '<note>&happy&</note>'; // The first entity reference "&" is an entity reference event, and the second entity reference "&", together with its following "happy", is treated as a text event. 41e41f4b71Sopenharmony_cilet textEncoder = new util.TextEncoder(); 42e41f4b71Sopenharmony_cilet arrbuffer = textEncoder.encodeInto(strXml); 43e41f4b71Sopenharmony_cilet that = new xml.XmlPullParser(arrbuffer.buffer as object as ArrayBuffer, 'UTF-8'); 44e41f4b71Sopenharmony_cilet str = ""; 45e41f4b71Sopenharmony_cifunction func(key: xml.EventType, value: xml.ParseInfo){ 46e41f4b71Sopenharmony_ci str += 'key:' + key +' value:' + value.getText() + ' '; 47e41f4b71Sopenharmony_ci return true; 48e41f4b71Sopenharmony_ci} 49e41f4b71Sopenharmony_cilet options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 50e41f4b71Sopenharmony_cithat.parse(options); 51e41f4b71Sopenharmony_ciconsole.log(str); 52e41f4b71Sopenharmony_ci``` 53e41f4b71Sopenharmony_ciBefore change: 54e41f4b71Sopenharmony_ci``` 55e41f4b71Sopenharmony_ciThe parsing result of &happy& is as follows: 56e41f4b71Sopenharmony_cikey: 4 (text event); value: &happy& 57e41f4b71Sopenharmony_ci``` 58e41f4b71Sopenharmony_ciAfter change: 59e41f4b71Sopenharmony_ci``` 60e41f4b71Sopenharmony_ciThe parsing results of &happy& are as follows: 61e41f4b71Sopenharmony_cikey: 9 (entity reference event): value: & 62e41f4b71Sopenharmony_cikey: 4 (text event); value: happy& 63e41f4b71Sopenharmony_ci``` 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ciTo use an entity reference event, use API version 12 or later and strictly comply with the entity reference event format in the XML file. Do not add regular text before the entity reference to form a text event. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ciIf you do not need to use entity reference events, add regular text before the entity reference in the XML file to form a text event or write the callback function. 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciEntity reference events: 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ciCurrently, only the following entity reference events corresponding to the five predefined entities in the XML file are supported: 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci``` 74e41f4b71Sopenharmony_ci< < less than 75e41f4b71Sopenharmony_ci> > greater than 76e41f4b71Sopenharmony_ci& & ampersand 77e41f4b71Sopenharmony_ci' ' apostrophe 78e41f4b71Sopenharmony_ci" " quotation mark 79e41f4b71Sopenharmony_ci``` 80e41f4b71Sopenharmony_ciIn addition, if regular text exists before an entity reference, they are treated as a text event as a whole. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ciExample: 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci``` 85e41f4b71Sopenharmony_ci<note>happy<></note>: start tag event, text event, and end tag event in sequence. 86e41f4b71Sopenharmony_ci<note><>happy</note>: start tag event, entity reference event, entity reference event, text event, and end tag event in sequence. 87e41f4b71Sopenharmony_ci``` 88