SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
 Apps
X
HANA App
>>>
Hadoop App
>>>
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
XSA Overview
+
-
XS Overview
+
-
Hello World Example
+
-
XS OData Service
+
-
HANA XSJS Service
+
-
Core Data Service
+
-
Others

XSJS - XML Parser

In this article we will show you an XSJS example to demonstrate – How to parse XML in XSJS service.
Note: To check all the examples on XSJS, read the article SAP HANA XSJS Examples

Introduction:

The SAP HANA XS JavaScript Utilities API provides a class for XML parsing.
$.util.SAXParser

With the XS JavaScript Utilities API $.util.SAXParser class, you can create a new parser object and parse the XML content of an XMLstring, an XML array buffer, or a $.web.Body object.
The following example shows how to use the XML parsing capabiliites of the $.util.SAXParser class:

Example:

Create an XSJS file and paste the below code.

//create a new $.util.SAXParser object 
var parser = new $.util.SAXParser(); 
//parse XML from String 
var parser = new $.util.SAXParser(); 
var xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' + 
           '<note noteName="Reminder Message">'+ 
               '<to>Roy</to>'+ 
               '<from>Thomas</from>'+ 
               '<heading>Reminder</heading>'+ 
               '<body>Do not forget the plan</body>'+ 
           '</note>'; 
var startElementHandlerConcat = ""; 
var endElementHandlerConcat = ""; 
var characterDataHandlerConcat = ""; 
parser.startElementHandler = function(name, atts) { 
    startElementHandlerConcat += name; 
    if (name === "note") { 
        startElementHandlerConcat += " noteName = '" + atts.noteName + "'"; 
    } 
    startElementHandlerConcat += "\n"; 
}; 
parser.endElementHandler = function(name) { 
    endElementHandlerConcat += name + "\n"; 
}; 
parser.characterDataHandler = function(s) { 
    characterDataHandlerConcat += s; 
}; 
parser.parse(xml); 
var body = 'Start: ' + startElementHandlerConcat + '</br>' + 
           'End: ' + endElementHandlerConcat + '</br>' + 
           'Charcter: ' + characterDataHandlerConcat + '</br>'; 
$.response.status = $.net.http.OK; 
$.response.contentType = "text/html"; 
$.response.setBody(body); 

Run XSJS Service:

Run the XSJS service and output will show the information as below:
SAP HANA XSJS XML Parsing

Download Full Source Code:

Click here to download the full source code. Follow the steps mentioned in “How to Run.txt” to run it.

Continue reading:



Support us by sharing this article.



Explore More
Close X
Close X

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

 © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy