Implement XML parsing
You can offload XML parsing to the native parser using the following functions.registerNativePlayerUtils()
To use native parsing the app must register the native functions. The registerNativePlayerUtils() function registers the app and allows it to call the Native XML parser. If the current platform supports native parsing the function returns true, otherwise false.
boolean isNativeXmlParserSupported(playerName: string, playerVersion: string)
playerName: Specifies the name of the player. The supported values is “shaka”.
playerVersion: Version of the player. For Shaka Player supported versions are 4.6.18 or 4.3.6.
Apps must check whether native support for XML parsing is available for a specific player and player version.
The native XML parser is currently supported for ShakaPlayer version 4.6.18 and 4.3.6
nativeParseFromString (manifest, expectedRoot)
The following arguments must be passed for shakaPlayer:
manifest: an ArrayBuffer that contains the downloaded manifest.
expectedRoot: The Expected root element of the parsed XML.
global.nativeParseFromString() provides the native implementation for XML parsing and is called by the player after registration.
unloadNativeXmlParser()
This unloadNativeXmlParser() function unloads the native parser cache. Call it when the app is done using the player. Typically, this is done as part of Player’s unload() function.
Integration Changes
Shaka Player
The native XML Parser is supported for versions4.6.18 and 4.3.6 of Shaka player. For information on using the Shaka Player in your app with all the required patches applied, see Play adaptive content (HLS/DASH) with Shaka Player.
To successfully integrate the XML Parser:
- Make sure that the Shaka player build has Shaka-Player-changes-for-Dash-nativization.patch that enables the hook to register the XML parsing function.
- As part of the nativization release drop, we are also making a polyfill addition:
DOMParserPolyfill. Make sure that DOMParserPolyfill.ts is picked as part of your application polyfills. - Make sure that the updated release of the MiscPolyfill.ts file is picked as part of your application polyfills. This polyfill has updates to remove reliance on the base
DomParserobject.
- ShakaPlayer v4.6.18: shaka-rel-v4.6.18-r2.11.tar.gz
- ShakaPlayer v4.3.6: shaka-rel-v4.3.6-r2.4.tar.gz
-
If not already defined, define the shaka player name and version in src/shakaplayer/ShakaPlayer.ts:
-
Optionally, you can define a flag to enable and disable native XML parsing. As an example, the following flag is used in the fifth step to enable native parsing.
-
Import and install
DOMParserPolyfill. -
Call
nativeParseFromString(). -
In your ShakaPlayer.ts file add a
load()function to validate whether the required functionality is available for native XML parsing. After all checks are validated, it callssetNativeFunctions()to pass the implementation from Shakaplayer to the native XML parser by callingnativeParseFromString(). ThesetNativeFunctions()accepts a function as an argument that is called by Shakaplayer during XML Parsing. -
In your ShakaPlayer.ts file add an
unload()function to check whether native XML parsing is enabled. If it is, callunloadNativeXmlParserto unload the parser.

