Computer Software

eg: UK or Brides UK or Classical Art or Buy Music or Spirituality
 
eg: UK or Brides UK or Classical Art or Buy Music or Spirituality
 
Business & Money
Technology
Women
Health
Education
Family
Travel
Cars
Entertainment
SD Editorials
Online Guide and article directory site.
Foodeditorials.com
Over 15,000 recipes & editorials on food.
Lyricadvisor.com
Get 100,000 Lyric & Albums.
  • Business & Money
    • A Guide to Business
    • Guide to Finance
    • Ideas for Marketing
    • Legal Guide
    • Guide to Insurance
    • Lettre De Motivation
    • Guide to the Stock Market
    • Human Resource Career
    • Sales Marketing
    • Forex & Trading
    • Advertising & Marketing
    • Startup Guide
  • Technology
    • Guide to Technology
    • Cell Phones
    • Computer Software
    • IT Hardwares
    • Internet
    • Online Security
    • Cameras
    • Search Engine Optimization
    • Science & Technology
  • Women
    • Guide to Women
    • Relationship Advice
    • Marriage
    • Jewelry
    • Pregnancy
    • Fashion Style
    • Divorce Guide
    • Wedding Guide
    • Dating Guide
    • Natural Beauty
  • Health
    • Guide to Health
    • Guide to Medical
    • Plastic Surgery
    • Weight Loss
    • Sports
    • Body Wellness
    • Cancer Treatment
    • Common Illness
    • Health & Lifestyle
  • Education
    • Military Service
    • Politics and Policy
    • Arts & Humanities
    • Education and Teaching
    • Learn Languages
    • Colleges & Universities
  • Family
    • Quality Home Improvement
    • Hobbies and Interests
    • Family Guide to
    • Pet Guide
    • Loans Guide
    • Credit Cards
    • Gardening Guide
    • Home Security
    • Real Estate
    • Home Decor
    • Gift & Present
  • Travel
    • The Travel Guide
    • Adventure Travel
    • Cruise Ships
    • Beach Holiday
    • Travel Accommodation
    • Holiday Destinations
  • Cars
    • Information on Cars
    • Traffic Violations
    • Auto Insurance
    • Trailers
    • Sport Cars
    • The Bikes
  • Entertainment
    • Entertainment Guide
    • World Music
    • Photo & Video
    • Television & Games

SoftXMLLib - JavaScript XML Library

    View: 


SoftXMLLib is a cross-browser JavaScript Library.



Any web developer dealing with XML data knows about hard job he must implement

in order to make things working perfectly in all browsers.

At time I wrote this libriary, I thought that IE is only browser with true

XPATH support but when I finished, my attitude to Mozilla browsers changed to

good.As a web developer, mostly client side scripting with advanced OOP JavaScript,

I have been developing Ajax applications for IE.

All was good until clients began to request cross-browser support. As any

programmer, I am lazy, so I decided to write such cross-browser libriary in

order to make my life easier and help other developers who are looking for

ready solutions.

You may ask me, why I did't use ready solutions like Sarrisa?

Pehaps I wanted to make things even easier, making web developer spending less

time on programming and more to have a pleassure outside job.Currently SoftXMLLib libriary API includes 9 methods and

6 properties to operate on XML Document.


Here I will give brief explanation on each:

Firstly include SoftXMLLib libriary into head section of your html file:



Create SoftXMLLib object:

var SoftXMLLib = new SoftXMLLib();

Methods

Example - load

SoftXMLLib.load("yourfile.xml")


if(SoftXMLLib.loadError!=0){

alert("XML file is invalid!");

return;

}


Loads given XML file.Example - loadXML

var xmlString = "
id="5">some text
";

SoftXMLLib.loadXML(xmlString)


if(SoftXMLLib.loadXMLError!=0){

alert("XML string is invalid!");

return;

}


Loads given XML string.Example - selectNodes

When there is no default namespace in XML document

var xmlString = "
name="Microsoft">some text
";

SoftXMLLib.loadXML(xmlString)

var xpath = "//company[@id='2']/@name";

matchedNodes = SoftXMLLib.selectNodes(xpath)


Selects nodes in loaded XML document that matched XPATH expression

In this example we select company's name where company id = 2

Only one node is returned by query, so we can access it like this:

alert(matchedNodes[0].attributes[0].name);

Will output Microsoft

alert(matchedNodes[0].self.getAttribute("name"));

Will output same as above Microsoft

When accessing attribute you can use one of following options:

attributes[0].attributename;

or

self.getAttribute("attributename")

When there is default namespace in XML document

Important note: Currently Opera does not support default

namespace, so this query won't work


You have to set two properties in order to use xpath in Mozilla browsers

SoftXMLLib.setPrefix("xsl");

SoftXMLLib.setNameSpace("http://www.w3.org/1999/XSL/Transform");

var xmlString = "
>
idref="34_6">MicrosoftUSA

id="2"

idref="34_7">OracleUSA
";

SoftXMLLib.loadXML(xmlString)

var xpath = "//xsl:company";

matchedNodes = SoftXMLLib.selectNodes(xpath)


In this example we select all company nodes in loaded XML document

for(var i = 0;i < matchedNodes.length;i++){

//output value of id and idref attributes

alert(matchedNodes[i].attributes[0].id + "=" +

matchedNodes[i].attributes[0].idref);

//will output 1 = 34_6 and 2 = 34_7

//output value of id attributes

another approach

alert(matchedNodes[i].self.getAttribute("id"));

//will output 1 and 2

//output number of attributes for each company node

alert(matchedNodes[i].self.attributes.length);

//will output 2 and 2

//output tagName of current element

alert(matchedNodes[i].self.nodeName);

//will output xsl:company and xsl:company

//output data in childnodes of each company node

alert(matchedNodes[i].self.getElementsByTagName("name")[0].childNodes[0].nodeValue);

//will output Microsoft and Oracle

}
Now we will change our xpath expression:

var xpath = "//xsl:name";

matchedNodes = SoftXMLLib.selectNodes(xpath)


In this example we select all name nodes in loaded XML document

for(var i = 0;i < matchedNodes.length;i++){

//output text in name nodes

alert(matchedNodes[i].innerText);

//will output Microsoft and Oracle

}
Now we will get all attributes in document:

var xpath = "//@*";

matchedNodes = SoftXMLLib.selectNodes(xpath)


for(var i = 0;i < matchedNodes.length;i++){

//output attribute name and attribute value

alert(matchedNodes[i].self.nodeName

+ "=" + matchedNodes[i].self.nodeValue);

//will output id=1 , idref=34_6 , id=2 , idref=34_7

}
Example - getDocAttributes

This method returns all attributes found in XML document

matchedNodes = SoftXMLLib.getDocAttributes()

for(var i = 0;i < matchedNodes.length;i++){

//output attribute name and attribute value

alert(matchedNodes[i].nodeName + "=" +

matchedNodes[i].nodeValue);

//will output id=1 , idref=34_6 , id=2 , idref=34_7

}
Example - getUniqueAttributes

This method returns only names of unique attributes found in XML document

matchedNodes = SoftXMLLib.getUniqueAttributes()

for(var i = 0;i < matchedNodes.length;i++){

//output attribute name

alert(matchedNodes[i].nodeName);

//will output id, idref

}
Example - getDocElements

This method returns names of all elements as they appear in XML document

matchedNodes = SoftXMLLib.getDocElements()

for(var i = 0;i < matchedNodes.length;i++){

//output element name

alert(matchedNodes[i].nodeName);

//will output xsl:company, xsl:name, xsl:location,.....

}
Example - getUniqueElements

This method returns names of unique elements in XML document

matchedNodes = SoftXMLLib.getUniqueElements()

for(var i = 0;i < matchedNodes.length;i++){

//output element name

alert(matchedNodes[i].nodeName);

//will output xsl:company, xsl:name, xsl:location

}
Example - Encode

This method returns ASC code of string passed to it char by char

Use this method with Ajax when you need to transfer content of xml tags in

other then english language

var xmlString = '
name="Microsoft">' + SoftXMLLib.Encode("not english

text") + '
';

SoftXMLLib.loadXML(xmlString)

ajaxObj = SoftXMLLib.createAjaxObject();

ajaxObj.open("POST","http://www.yourserver.com/testAjax.asp",true);

ajaxObj.onreadystatechange=function() {

if (ajaxObj.readyState==4) {

alert(ajaxObj.responseText);

}

}

ajaxObj.send(softXMLLib.DOM);



In order to send XML data with XMLHTTP object you have to use DOM property of

SoftXMLLib objectExample - Decode

This method returns string from ASC code passed to it

Use this method with Ajax when you need to get content of xml tags in other

then english language
More Articles from
Free Digital Scrapbooking Software
Life Made Simple Tvb
Life The Online Game
Light With Magnifying Glass
Linux Data Recovery Software
Linux For Free Download
Linux User Password Change
Lion Vs A Tiger
List Of Gluten Free Products
List Of Psp Movies
List Of Small Businesses
List Of Software Applications
List Of Software Consultants
List Of Software Packages
List Of Windows Commands
Living Part Of Life
Load And Stress Testing
Local Disk Open With
Logitech Quickcam Installation Software
Look At Free Movies
Looking For An Internship
» More on
The Best Software Writing
  • Related Articles
  • Author
  • Most Popular
Gregory Movsesyan has sinced written about articles on various topics from Software. Speciality:Internet Programmer (6 years of experiencein scripting languages and VB ).Education:1992-1995: Bar-Ilan University, Ramat Gan.Field of Specialization:Operating Systems: Windows NT, Windows XP/200. Gregory Movsesyan's top article . to your Favourites.
Advertising Ideas For Small Business
I hope these tips have been of use to you. The internet is only going to get stronger over the next few years. Jump on board now or get left behind
 
A Guide to Business | Guide to Technology | Guide to Women | Guide to Health | Family Guide to | Travel & Vacations | Information on Cars

EditorialToday Computer Software has 2 sub sections. Such as Software and All Microsoft Softwares. With over 20,000 authors and writers, we are a well known online resource and editorial services site in United Kingdom, Canada & America . Here, we cover all the major topics from self help guide to A Guide to Business, Guide to Finance, Ideas for Marketing, Legal Guide, Lettre De Motivation, Guide to Insurance, Guide to Health, Guide to Medical, Military Service, Guide to Women, Pet Guide, Politics and Policy , Guide to Technology, The Travel Guide, Information on Cars, Entertainment Guide, Family Guide to, Hobbies and Interests, Quality Home Improvement, Arts & Humanities and many more.
About Editorial Today | Contact Us | Terms of Use | Submit an Article | Our Authors