angularjs ajax isxml,GitHub - johngeorgewright/angular-xml: XML module for AngularJS

68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6a6f686e67656f7267657772696768742f616e67756c61722d786d6c2f6d61737465722e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f686e67656f7267657772696768742f616e67756c61722d786d6c2f6d61737465722e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f616e67756c61722d786d6c2e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f626f7765722f762f616e67756c61722d786d6c2e737667

68747470733a2f2f696d672e736869656c64732e696f2f67656d6e617369756d2f6a6f686e67656f7267657772696768742f616e67756c61722d786d6c2e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f616e67756c61722d786d6c2e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f6261646765732e677265656e6b65657065722e696f2f6a6f686e67656f7267657772696768742f616e67756c61722d786d6c2e737667

68747470733a2f2f73617563656c6162732e636f6d2f62726f777365722d6d61747269782f616e67756c61722d786d6c2e737667

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 : "" - 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 _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 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.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;

});

});

Blogs
  • {{blog._id}} - {{blog._name}}

Installation

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

Then there are 3 optoins:

Download the latest tag.

Use bower: bower i --save angular-xml

Or use jsDelivr CDN: //cdn.jsdelivr.net/npm/angular-xml@2.2.2/angular-xml.min.js

Contributing

To contribute to the project take the following steps:

Fork the project.

Create a branch specific for your change(s).

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值