xml2js#Builder TypeScript Examples

The following examples show how to use xml2js#Builder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: status.ts    From OpenTibiaLoginServer with MIT License 6 votes vote down vote up
builder = new Builder({
        rootName: "xml",
        renderOpts: {
            'pretty': false
        },
        xmldec: {
            'version': '1.0'
        }
    });
Example #2
Source File: Connection.ts    From huawei-lte-api-ts with GNU Lesser General Public License v3.0 6 votes vote down vote up
private createRequestXml(data: Record<string, unknown>): string {
        /* Force empty tags instead of selfclosing tags */
        const builder = new Builder(<any>{
            renderOpts: {
                pretty: false,
                indent: ' ',
                newline: '\n',
                allowEmpty: true
            }
        });
        return builder.buildObject({
            request: data
        });
    }
Example #3
Source File: xml-write.ts    From attranslate with MIT License 5 votes vote down vote up
export function writeXmlResourceFile(
  xmlFile: XmlFile,
  args: WriteTFileArgs,
  auxData: XmlAuxData | null
) {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const xml2js = require("xml2js");
  const stringIndent = " ".repeat(
    auxData?.detectedIntent ?? DEFAULT_XML_INDENT
  );
  const options: OptionsV2 = {
    ...sharedXmlOptions,
    headless: true,
    renderOpts: {
      pretty: true,
      indent: stringIndent,
    },
  };
  // See https://github.com/oozcitak/xmlbuilder-js/wiki/Builder-Options for available xmlBuilderOptions
  const xmlBuilderOptions = {
    noValidation: false,
    noDoubleEncoding: true,
  };
  const mergedOptions = { ...options, xmlBuilderOptions };
  const builder: Builder = new xml2js.Builder(mergedOptions);
  const rawXmlString: string = builder.buildObject(xmlFile);
  let xmlHeader: string = DEFAULT_XML_HEADER + "\n";
  if (auxData) {
    if (auxData.xmlHeader) {
      xmlHeader = auxData.xmlHeader + "\n";
    } else {
      xmlHeader = "";
    }
  }
  const xmlString = `${xmlHeader}${removeBlankLines(rawXmlString)}\n`;
  writeManagedUtf8({ path: args.path, utf8: xmlString });
}