npm.io
0.0.7 • Published 4 years ago

xml-pipe

Licence
MIT
Version
0.0.7
Deps
1
Size
18 kB
Vulns
0
Weekly
0
Stars
1
DeprecatedThis package is deprecated

XmlPipe

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 XmlPipe

Use npm to install the package:

npm i xml-pipe

Or install using ng add:

ng add xml-pipe

Usage

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

@NgModule({
 declarations: [
   AppComponent
 ],
 imports: [
   BrowserModule,
   XmlPipeModule
 ],
 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><adress><street>742 Evergreen Terrace</street><city>Springfield</city></adress></character>

Credits

This project is based on xmlbuilder2.

Keywords