www.webdeveloper.com
Results 1 to 3 of 3

Thread: parse XML in Javascript withour DOM

  1. #1
    Join Date
    Feb 2012
    Posts
    1

    parse XML in Javascript withour DOM

    hi,

    I am using Team-site and it does not support DOM. i need to read a xml file through java script and unable to do that without DOM. Is there are method for doing this?

    Thanks,
    ayush

  2. #2
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    373
    For an example of a parsing application in javascript try abcnwc.htm. You would need regular expressions to identify the elements of XML code to deal with them as well as identify code which is an error. After setup, the parsing in the above link is in the lines 544-822.

    Good luck!

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    its lots of hand-tuning, but it can be done for specific applications in a reasonable amount of time.

    for example,
    getting the head and body tag content and getting a class from the body tag using pure js:


    Code:
    	 
     fileValue=document.documentElement.innerHTML;
    
     myPage={};
    
    	//head and body html:
    	var head=(fileValue.split(/<head[^>]*>/i)[1]||"").split(/<\/head>/i)[0]||"";
            myPage.head=head;
    
    	var body=(fileValue.split(/<body[^>]*>/i)[1]||"").split(/<\/body>/i)[0]||"";
    	   if(body){myPage.body=body||333;}
    	
    	//body class:
    	var bc=fileValue.match(/<body[^>]*>/i);
    	 if(bc){bc=(bc[0].split("class=")[1]||"").slice(1).split(/['"]/)[0]; }
    	 if(bc){ myPage.bodClass=bc;}
    
    alert(  JSON.stringify( myPage, null, "\t" )  );
    Last edited by rnd me; 02-29-2012 at 04:42 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles