npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-xml

v2.2.5

Published

XML module for AngularJS.

Downloads

1,137

Readme

Codecov Build Status NPM Version Bower Dependencies License Greenkeeper badge

Sauce Test Status

angular-xml

XML module for AngularJS.

As of v2.0.0 this module relies on the X2JS module

Supplies the X2JS library as a service and provides a HTTP interceptor to convert all XML responses in to JSON.

Configuring the X2JS service

angular
  .module('myMod', ['xml'])
  .config(function (x2jsProvider) {
    x2jsProvider.config = {
      /*
      escapeMode               : true|false - Escaping XML characters. Default is true from v1.1.0+
      attributePrefix          : "<string>" - Prefix for XML attributes in JSon model. Default is "_"
      arrayAccessForm          : "none"|"property" - The array access form (none|property). Use this property if you want X2JS generates an additional property <element>_asArray to access in array form for any XML element. Default is none from v1.1.0+
      emptyNodeForm            : "text"|"object" - Handling empty nodes (text|object) mode. When X2JS found empty node like <test></test> it will be transformed to test : '' for 'text' mode, or to Object for 'object' mode. Default is 'text'
      enableToStringFunc       : true|false - Enable/disable an auxiliary function in generated JSON objects to print text nodes with text/cdata. Default is true
      arrayAccessFormPaths     : [] - Array access paths. Use this option to configure paths to XML elements always in "array form". You can configure beforehand paths to all your array elements based on XSD or your knowledge. Every path could be a simple string (like 'parent.child1.child2'), a regex (like /.*\.child2/), or a custom function. Default is empty
      skipEmptyTextNodesForObj : true|false - Skip empty text tags for nodes with children. Default is true.
      stripWhitespaces         : true|false - Strip whitespaces (trimming text nodes). Default is true.
      datetimeAccessFormPaths  : [] - Datetime access paths. Use this option to configure paths to XML elements for "datetime form". You can configure beforehand paths to all your array elements based on XSD or your knowledge. Every path could be a simple string (like 'parent.child1.child2'), a regex (like /.*\.child2/), or a custom function. Default is empty
      */
    };
  });

For any more information on how to configure and use the X2JS service, see their project.

Accessing the X2JS service

angular
  .module('myMod', ['xml'])
  .factory('someFactory', function (x2js) {
    var xmlDoc = x2js.json2xml(
      {
        MyRoot : {
          MyChild : 'my_child_value',
          MyAnotherChild: 10,
          MyArray : [ 'test', 'test2' ],
          MyArrayRecords : [
            {
              ttt : 'vvvv'
            },
            {
              ttt : 'vvvv2'
            }
          ]
        }
      }
    );
  });

Read the docs on how to use it.

Using the HTTP interceptor

The HTTP interceptor will convert all your XML responses in to a JavaScript Object.

<!-- blogs.xml -->
<blogs>
  <blog name="my first blog" id="1"/>
</blogs>
// blogs.js
angular
  .module('blogs', ['xml'])
  .config(function ($httpProvider) {
    $httpProvider.interceptors.push('xmlHttpInterceptor');
  })
  .controller(function ($scope, $http) {
    $http.get('blogs.xml').success(function (data) {
      $scope.blogs = data.blogs.blog;
    });
  });
<!doctype html>
<html lang="en" ng-app="blogs">
    <head>
        <title>Blogs</title>
        <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
        <script src="bower_components/x2js/xml2json.min.js"></script>
        <script src="bower_components/angular-xml/angular-xml.min.js"></script>
        <script src="blogs.js"></script>
    </head>
    <body ng-controller="BlogsCtrl">
        <ul>
            <li ng-repeat="blog in blogs">
                {{blog._id}} - {{blog._name}}
            </li>
        </ul>
    </body>
</html>

Installation

First acquire the X2JS library (this comes bundled with the bower option described next)

Then there are 3 optoins:

  1. Download the latest tag.
  2. Use bower: bower i --save angular-xml
  3. Or use jsDelivr CDN: //cdn.jsdelivr.net/npm/[email protected]/angular-xml.min.js

Contributing

To contribute to the project take the following steps:

  1. Fork the project.
  2. Create a branch specific for your change(s).
  3. Submit a pull request to my master branch and we can begin the process of merging.

When submitting, please make sure your code is covered by tests.

Tests

The unit tests run with Karma and the E2E tests run with Protractor.

Update the webdriver

npm run update-webdriver

Run the test suite

npm test

Or, to watch your files and test automatically:

npm run dev

Compiling

The source file angular-xml.js can be minifed and checked for problems using a grunt command. First make sure you have installed all npm dependencies npm i. Then run grunt.

Git Hooks

There is a git hook available for shell environments that will automatically lint, test and compile the xml module when commiting it. To use it simply link it in to the git hook directory.

npm run hook-git

# And... of you want to remove the hook
npm run unhook-git

Now when you change the angular-xml.js file and commit it, it will be linted, tested and if all is OK, then compiled and the minified version wil be added to your commit.