0.0.9 • Published 2 years ago

ngx-xml-pipe v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NgxXmlPipe

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 { }

2) Use the xml pipe in your template expression.

{{ value | xml : prettyPrint : root }}

Arguments

ParamTypeDefault ValueDetails
valueobjectThe object to be displayed in XML representation.
prettyPrintbooleanfalseWhether the XML elements should be indented according to their level.
rootstringName 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.

0.0.9

2 years ago

0.0.8

2 years ago