XML Repository

Category Archives: XML Parsing

Steps to Convert Text to XML

by Sir on April 2, 2011

XML is a set of rules which with advice of computers makes argument files readable. For assorted business purposes you crave to advance XML files. If you readily do not accept XML files you may aswell catechumen argument to XML. In adjustment to encode argument abstracts to use on the Internet XML files are commonly used. To catechumen argument abstracts to XML is a accepted accident for computer programmers as able-bodied as web developers.

Steps to Catechumen Argument to XML

You can catechumen argument files to XML by beat “save as” advantage in your chat processor. This affection could be acclimated in assorted versions of Microsoft Chat 2003 or Microsoft Chat 2007.

In the “save as type”, bead down box you accept to baddest “XML file”.

Save your argument book as an XML book by beat on “enter”. In case, your computer does not accept Microsoft Chat 2003 or Microsoft Chat 2007, you can download accordant software for assuming this function.

Advantages of Argument to XML Conversion

Java Mapping concepts Understanding

by Sir on March 24, 2011

Mapping is the way of transforming one XML structure to another XML Structure. As a part of it we do certain operations like breaking child nodes and attaching them to its parent node and more in an XML structure.

In XI/PI we have the following mapping techniques

1. Graphical Mapping
2. ABAP Mapping
3. JAVA Mapping and
4. XSLT Mapping.

Among all the above mapping techniques, JAVA mappings improve the performance and are preferred as they get executed on J2EE engine directly. But in case of graphical mapping, XI/PI converts the mapping program into executable Java code internally based on graphical design and executes it on J2EE engine making it comparatively less efficiency. Java mappings are more useful when performance of integration server is concerned during runtime. Java mappings are Parsing Programs that can be developed in NWDS (NetWeaver Developer Studio), import as .jar files and can be used in the mapping part of Integration Repository. NWDS provides suitable Java environment and higher level tools to parse XML documents through the Simple API for XML (SAX) and the Document Object Model (DOM) interfaces. The SAX and DOM parsers are standards that are implemented in several different languages. In the Java programming language, you can instantiate the parsers by using the Java API for XML Parsing (JAXP).

JAVA mapping can be done in two ways:

1. DOM Parsing
2. SAX Parsing

At the core of the DOM API are the Document and Node interfaces. A Document is a top-level object that represents an XML document. The Document holds the data as a tree of Nodes, where a Node is a base type that can be an element, an attribute, or some other type of content. The Document also acts as a factory for new Nodes. Nodes represent a single piece of data in the tree, and provide all of the popular tree operations. You can query nodes for their parent, their siblings, or their children. You can also modify the document by adding or removing Nodes.

SAX PARSING TECHNIQUE

SAX (Simple API for XML) is an event-driven model for processing XML. The SAX model is quite different. Rather than building a complete representation of the document, a SAX parser fires off a series of events as it reads the document from beginning to end. Those events are passed to event handlers, which provide access to the contents of the document.

Event Handlers

There are three types of event handlers: DTD Handlers, for accessing the contents of XML Document-Type Definitions; Error Handlers, for low-level access to parsing errors; and, by far the most often used, Document Handlers, for accessing the contents of the document. A SAX processor will pass the following events to a Document Handler:

– The start of the document.
– A processing instruction element.
– A comment element.
– The beginning of an element, including that element’s attributes.
– The text contained within an element.
– The end of an element.
– The end of the document.
Advantages and Disadvantages SAX

Advantages:

DOM
Advantages:

1. It is good when random access to widely separated parts of a document is required.
2. It supports both read and write operations. >

Disadvantage:

It is memory inefficient because DOM consumes more memory to construct the XML tree Object in the memory corresponding to the input XML its not advisable to use for parsing large XML documents In that case SAX is preferred over DOM.

1. It is simple to program.
2. It is memory efficient as SAX parser does not keep any of the document tree in memory.

Disadvantage:

The data is broken into pieces and clients never have all the information as a whole unless they create their own data structure.

Differences between SAX and DOM parser at a glance

SAX

1. Parses node by node
2. Doesn’t store the XML in memory
3. We cant insert or delete a node
4. Top to bottom traversing

DOM

1. Stores the entire XML document into memory before processing
2. Occupies more memory
3. We can insert or delete nodes4. Traverse in any direction.

Javascript Feature: Read Xml String, Parse, And Set Elements To Values

by Sir on February 11, 2011

JavaScript Feature: Read XML String, Parse, and Set Elements to Values

Who is this for?

Getting a fully functional script that actually reads in XML, parses it, and then sets element values is not easy to find on the Web. I searched for hours, but was only able to find bits and pieces to put together a function. So if you are looking to have a PHP script create an XML document filled with variables and HTML, then this code is for you.

What are all the files I need to evaluate this code?

The parts involved in this example code are a PHP file, “AJAX.php”, and an HTML file, “AJAX.htm”, with a few JavaScript functions.

  • The PHP file creates the XML string. Note: all values should be URL encoded to ensure HTML strings do not break the code.
  • The HTML file provides the elements, and the following JavaScript to render the XML.
    • JavaScript function to create the XMLHttpRequest: get_oXMLHTTP().
    • JavaScript function to call the PHP file and retreive the responseText: getAJAXContent_XML().
    • JavaScript function to create an XML object from the responseText: loadXMLString().
    • JavaScript function to run through the XML object and set the elements to the values: setElementValues().
    • JavaScript function that decode the URL encryption that is put on all the nodes of the XML object.

PHP and JavaScript Coordination

There is some coordination between the PHP file, and the JavaScript funciton setElementValues(). The tags that hold the key information in the XML document are “formID” and “formVal”. More appropriate names would be elementID and elementValue, since these nodes cooresponde to the elements. The setElementValues() function gets the values of these two nodes, and based on the value for formID, that element in the HTML document will have its innerHTML set to the value found in the formVal node. If element name does not match the formID value, then the value is read, but never set.

Demo and Download

O.K. That is a lengthy intro, and if you are like me you just want the code, and to see an example. If you feel like you need some explanation, then you RTFM (Read The Freaking Manual). So let’s get to the good stuff… the example. Below is some HTML with a few element tags. Click the “Run AJAX XML Script” and see what happens. After that, down load the script, and open it in your editor.

This form will not work in this article. Please use the links at the bottom of the article to use the function examples.

___________________________________________________

E-Mail Receipt

To:
From:
Subject:
Message:

____________________________________________________

How does it work?

  1. Create an XMLHttpRequest Object
    The function “get_oXMLHTTP()” is a standardized script that you can get from W3C.org. It simply tests the browser type, and based upon that creates a XMLHttp object and returns it to the caller. We will go over the caller towards the end. function get_oXMLHTTP(){
    var output = null;
    try{// Firefox, Opera 8.0+, Safari
    output = new XMLHttpRequest();
    }catch(e){ // Internet Explorer
    try{
    output = new ActiveXObject(“Msxml2.XMLHTTP”);
    }catch (e){
    output = new ActiveXObject(“Microsoft.XMLHTTP”);
    }
    }
    return output;
    }
  2. Call the PHP file, and retrieve the responseText
    The function “getAJAXContent_XML()” is a standardized script that you can get from W3C.org. It simply calls the PHP and retrieves the XML string. What is different is that it uses loadXMLString() to load the XML sting into an object “XMLDoc”, and then sets the document elements (Marked in red). function getAJAXContent_XML(objHTTP, url){
    if (objHTTP != null){
    objHTTP.open(“POST”, url, true);
    objHTTP.send(null);
    objHTTP.onreadystatechange = function(){
    if(objHTTP.readyState == 4){
    loadXMLString(objHTTP.responseText);
    setElementValues();
    }
    }
    }
    }
  3. Create an XML Object from string
    The function “get_oXMLHTTP()” is a standardized sceipt that you can get from W3C.org. It simply tests the browser type, and based upon that it loads the XML string into XMLDoc. Where the Microsoft XMLDOM just loads the string, the non IE browsers creates a DOMParser, and then has the object to “parseFromString”, which is pretty litteral in its name. So no need for further explaination. Just notice that the function needs to know the type, and that is where “text/xml” is key in transfering the string into an actual XML object. Up to this point, the string is only a string properly formated as an XML document. function loadXMLString(xmlData) {
    try { //Internet Explorer
    xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
    xmlDoc.async = “false”;
    xmlDoc.loadXML(xmlData);
    }catch(e){ //Firefox et. all
    try {
    parser = new DOMParser();
    xmlDoc = parser.parseFromString(xmlData, “text/xml”);
    }catch(e){
    alert(e.message)
    }
    }
    }
  4. Run through the XML object and set the document element innerHTML attribute
    This function uses the XMLDoc object loaded via loadXMLString(). Another object is created, “oRV”, to hold the entire node that is named “elementValues”. Another object, “oV”, is created to hold the child node list. The node list is made up of children using the “record” tag. Looping through the child node list we get the child nodes for “formID” and “formVal”. The values are decoded. If the document element exists, then it sets that document element to the formVal pulled from the XML object. function setElementValues(){
    var oRV = xmlDoc.getElementsByTagName(“elementValues”);
    var oV = oRV[0].childNodes;
    var formID = “”;
    var value = “”;for (i = 0; i < oV.length; i++){
    oFormID = oV[i].getElementsByTagName(“formID”);
    oFormVal = oV[i].getElementsByTagName(“formVal”);
    formID = URLDecode(oFormID[0].text);
    formVal = URLDecode(oFormVal[0].text);
    if(document.getElementById(formID)){ document.getElementById(formID)[removed] = formVal; }
    }
    }
  5. Decoding the URL encrypted node values
    The function “URLDecode()” simply uses the escape() JavaScript function, and translates the URL encoded content into a HTML compatible string. The only thing not escaped from the PHP urlencode are the plus “+”. Using the JavaScript function replace(), the string is quickly cleaned of any visible “+” signs. Make sure you use proper HTML codes for the “+” sign, which is “&#43;”. function URLDecode(val){
    var output = “”;
    output = unescape(val);
    output = output.replace(/+/g, ” “);
    return output;
    }

JQuery XML Parsing is Easy

by Sir on February 3, 2011

When learning or operating AJAX, there always the time for anyone or students finding it really frustrating to parse complex statements or scripts. The fact is that there is actually simple solution for it available anyone can try, especially for those whom spending more of their time utilizing and operating AJAX – it is by using jQuery. Many have experienced using JQuery, and most of them get really satisfied with the simplest solution offered.

By using JQuery, things should be easier and more convenient for both beginner and advanced people to read the scripts in simple way. You may use the JQuery to simplify the complicated scripts to analyze or adding some new statements to it. Get your work or project simplified and now you can just understand any complex statements in a glimpse by using JQuery.

If you’re wondering to know more about Jquery, the chance is that now you can just easily to find detailed information about it from many sources, including online sources. Many sites would likely to inform you about JQuery, including also some offers comprehensive online course to jquery xml parsing where you may get complete tutorial and help doing xml parsing with JQuery anytime you need it.…

Parse XML with JQuery

by Sir on February 1, 2011

If you’re on your way of learning AJAX or is currently working on with XML, you should know about JQuery then. Unlike the other basic applications which offer some new utilities and advanced functions, JQuery comes with the most basic help most programmers exactly need it. JQuery is designed to help programmers in parsing and understanding XML statements. For you whom have always being troubled in parsing complex statements, now you know where to go for best solution on it.

With only few clicks of your finger, now you may easily to count on the JQuery to parse and make the codes more compact so you may analyze and making any arrangements you want. When you receive the text from callback, JQuery will make it easier for you to understand every statement with the DOM (Document Object Model). Once you use JQuery, parsing and understanding XML texts wouldn’t anymore a problem for you. This will get you easier doing your XML project.

Take your time learning more about jquery parse xml and how you can make advantages from this simple but amazing application. Many sources you can go out there for more information about JQuery, including also complete guide to it if you dig these sites deeper. …