Skip to content

Angular Pipe which converts a value into its XML-format representation.

License

Notifications You must be signed in to change notification settings

fbernack/ngx-xml-pipe

Repository files navigation

NgxXmlPipe

npm MIT licensed

Angular Pipe which converts a value into its XML-format representation.

Installation

Peer dependency

The package uses the peer dependency xmlbuilder2, so this must be installed first.

npm i xmlbuilder2

Install NgxXmlPipe

Use npm to install the package:

npm i ngx-xml-pipe

Or install using ng add:

ng add ngx-xml-pipe

Usage

  1. Register the NgxXmlPipeModule in your app module.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { NgxXmlPipeModule } from 'ngx-xml-pipe';

@NgModule({
 declarations: [
   AppComponent
 ],
 imports: [
   BrowserModule,
   NgxXmlPipeModule
 ],
 providers: [],
 bootstrap: [AppComponent]
})
export class AppModule { }
  1. Use the xml pipe in your template expression.
{{ value | xml : prettyPrint : root }}

Arguments

Param Type Default Value Details
value object The object to be displayed in XML representation.
prettyPrint boolean false Whether the XML elements should be indented according to their level.
root string Name of an optional root element to be added.

Examples

Default usage

foo = { foo :  'bar' }
{{ foo | xml }}

Result:

<?xml version="1.0"?><foo>bar</foo>

Additional root element

Note: If your object has multiple properties at the first level, a root element must be added, otherwise a valid XML document cannot be displayed.

foo = { name:  "Lisa Simpson", address: { street :  "742 Evergreen Terrace", city:  "Springfield" }}
{{{ foo : false : 'character' }}}

Result:

<?xml version="1.0"?><character><name>Lisa Simpson</name><address><street>742 Evergreen Terrace</street><city>Springfield</city></address></character>

Credits

This project is based on xmlbuilder2.

About

Angular Pipe which converts a value into its XML-format representation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published