473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XML Parser/validator in Java script

44
Hi All,

I want some good implementation in Javascript for validating XML data.

If user enters some text in the textarea control, before XML data is saved in the database, the validation should happen in terms of whether it is well-formed or not, etc. Can you please point me to the same?

Thanks in advance!

Regds,
Sivakumar
May 7 '08 #1
10 1956
acoder
16,027 Expert Mod 8TB
Use a server-side language to do the validation. You could make an Ajax request to validate the XML string.
May 7 '08 #2
siva538
44
Use a server-side language to do the validation. You could make an Ajax request to validate the XML string.
Hi acoder,

This is my last resort. I want to implement using client side validation.

Please help !

Thanks,
Sivakumar
May 7 '08 #3
acoder
16,027 Expert Mod 8TB
See http://www.w3schools.com/Xml/xml_validator.asp
May 7 '08 #4
rnd me
427 Expert 256MB
if you run it through a parser, the parser will error out if the xml is semantically broken.

true validity is harder to validate, and i am not aware of any javascript-based validator, not that it's impossible.


this might interest you for the well-formedness part:
Expand|Select|Wrap|Line Numbers
  1. function makeWellFormed(str){
  2.     var b = document.createElement("b");
  3.     b.innerHTML = str;
  4.   return b.innerHTML;
  5. }
  6.  
  7. makeWellFormed("<ber>frefg</ber") //returns "<ber>frefg</ber>"
  8. makeWellFormed("<ber>frefg</ber>") //returns "<ber>frefg</ber>"
  9. makeWellFormed("<ber>frefg") //returns "<ber>frefg</ber>"
  10.  
May 8 '08 #5
siva538
44
if you run it through a parser, the parser will error out if the xml is semantically broken.

true validity is harder to validate, and i am not aware of any javascript-based validator, not that it's impossible.


this might interest you for the well-formedness part:
Expand|Select|Wrap|Line Numbers
  1. function makeWellFormed(str){
  2.     var b = document.createElement("b");
  3.     b.innerHTML = str;
  4.   return b.innerHTML;
  5. }
  6.  
  7. makeWellFormed("<ber>frefg</ber") //returns "<ber>frefg</ber>"
  8. makeWellFormed("<ber>frefg</ber>") //returns "<ber>frefg</ber>"
  9. makeWellFormed("<ber>frefg") //returns "<ber>frefg</ber>"
  10.  
Thanks for the reply! the function you provided just returns the wellformed strings. I was looking for some xml validation code.
May 8 '08 #6
acoder
16,027 Expert Mod 8TB
Thanks for the reply! the function you provided just returns the wellformed strings. I was looking for some xml validation code.
Have you seen the link I posted?
May 8 '08 #7
siva538
44
Have you seen the link I posted?
Yes! I have seen it. But the problem with that is, it is a validation of xml using a DTD schema. I was looking for a gereric validator for just well formedness.

In the mean time we had written a validator ourselves. But unfortunately that was not very robust :(

Please help if you can !
May 8 '08 #8
acoder
16,027 Expert Mod 8TB
Yes! I have seen it. But the problem with that is, it is a validation of xml using a DTD schema. I was looking for a gereric validator for just well formedness.
The first section (Syntax check your XML) does exactly that!
May 9 '08 #9
siva538
44
The first section (Syntax check your XML) does exactly that!
This is right on spot and thanks for pointing me to this. Earlier when you posted this I didn't look at it correctly. But now it really solved the problem.

Thank you very very much for helping me on this !!
May 12 '08 #10
acoder
16,027 Expert Mod 8TB
No problem, you're welcome. Glad I was able to help.
May 12 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: mkremser | last post by:
Hi NG! In a XSD, we (try to) specify that a node ("BsqCallInfo") has two attributes and can have any nodes as its children: <xsd:element name="BsqCallInfo"> <xsd:complexType> <xsd:choice...
3
by: Boris Kester | last post by:
Hello, I tried to validate this page: http://www.traveladventures.org/xhtml/ daralhajar01.html on validator.w3.org and got a message that the page is not valid transitional xhtml. However, after...
25
by: Ali-R | last post by:
Hi, Is there a parser which parses CSV files? Thanks for your help. Reza
2
by: Herve MAILLARD | last post by:
Hi, J'ai un bouton ASPX qui doit déclencher un script java. I have an ASPX button running a javascript. To do this, I have added in the codebehind :...
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
4
by: M Arora | last post by:
Hi All I am using Xerces parser to convert my xml to the output given below and for this i am using the xslt. How shall i create href attribute in xerces parser? When i am using MSDOM parser...
5
by: gullyou | last post by:
Sorry I crossposted this to java group. Didn't know distinction between Java & Javascript Hi, I'm not a Java script programmer but have this web page with a form form that includes a...
3
by: Mike Collins | last post by:
Is it possible to use a required field validator and have it make a user answer a comment field based on a drop down value picked? For instance, if the user selects "It was terrible", make them...
1
by: Prasanth Nair | last post by:
hi, When I add the following in struts-config.xml, I am getting the below mentioned error while starting the server. /***********************Struts entry**********************/ <plug-in...
0
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.