11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- import { XMLParser } from "fast-xml-parser" ;
54import { unfence } from "./unwrappers.js" ;
65import { filenameOrFileToContent } from "./unwrappers.js" ;
76import type { WorkspaceFile , XMLParseOptions } from "./types.js" ;
@@ -16,14 +15,14 @@ const dbg = genaiscriptDebug("xml");
1615 * @param options - Optional configuration for the XML parser
1716 * @returns The parsed XML object or defaultValue if an error occurs
1817 */
19- export function XMLTryParse (
18+ export async function XMLTryParse (
2019 text : string | WorkspaceFile ,
2120 defaultValue ?: unknown ,
2221 options ?: XMLParseOptions ,
2322) {
2423 try {
2524 // Try parsing the text and return the result or defaultValue
26- return XMLParse ( text , options ) ?? defaultValue ;
25+ return ( await XMLParse ( text , options ) ) ?? defaultValue ;
2726 } catch ( e ) {
2827 // Return the default value if parsing fails
2928 dbg ( `error: %s` , e ?. message ) ;
@@ -38,11 +37,13 @@ export function XMLTryParse(
3837 * @param options - Configuration options for the XML parser. These options are merged with the default parser settings.
3938 * @returns The parsed XML object.
4039 */
41- export function XMLParse ( text : string | WorkspaceFile , options ?: XMLParseOptions ) {
40+ export async function XMLParse ( text : string | WorkspaceFile , options ?: XMLParseOptions ) {
4241 text = filenameOrFileToContent ( text ) ;
4342 // Remove specific markers from the XML string for cleaner processing
4443 const cleaned = unfence ( text , "xml" ) ;
4544
45+ const { XMLParser } = await import ( "fast-xml-parser" ) ;
46+
4647 // Create a new XMLParser instance with the specified options
4748 const parser = new XMLParser ( {
4849 ignoreAttributes : false , // Do not ignore XML attributes
0 commit comments