ojp-sdk
    Preparing search index...

    Class XmlSerializer

    Serializes JavaScript objects to XML format with configurable options.

    The XmlSerializer provides methods to convert JavaScript objects into XML strings using a configurable XML configuration. It includes automatic tag name transformation to handle different naming conventions.

    // Basic usage
    const serializer = new XmlSerializer();
    const xmlString = serializer.serialize({
    name: "John",
    age: 30
    }, "person");

    // With custom configuration
    const customConfig = {
    indent: ' ',
    newline: '\n'
    };
    const serializerWithConfig = new XmlSerializer(customConfig);
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    xmlConfig: XML_Config

    Methods

    • Serializes a JavaScript object to XML format

      Parameters

      • obj: Record<string, any>

        The object to serialize

      • wrapperNodeName: string

        The name of the root XML element

      Returns string

      XML string representation of the object

      const serializer = new XmlSerializer();
      const xml = serializer.serialize({
      firstName: "John",
      lastName: "Doe"
      }, "person");
      // Returns: '<person><firstName>John</firstName><lastName>Doe</lastName></person>'
    • Transforms a tag name to camelCase format for XML serialization

      This method handles special cases like OJP prefixes and preserves uppercase-only tags. It converts hyphenated or underscored names to camelCase while ensuring the first character is lowercase.

      Parameters

      • tagName: string

        The original tag name to transform

      Returns string

      Transformed tag name in camelCase format

      // Transform various tag name formats
      XmlSerializer.transformTagName('OJP_Feature'); // Returns: 'OJP_Feature'
      XmlSerializer.transformTagName('FIRST_NAME'); // Returns: 'FIRST_NAME'
      XmlSerializer.transformTagName('first-name'); // Returns: 'firstName'
      XmlSerializer.transformTagName('user_name'); // Returns: 'userName'