473,839 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Parser/validator in Java script

44 New Member
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 1976
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
See http://www.w3schools.com/Xml/xml_validator.asp
May 7 '08 #4
rnd me
427 Recognized Expert Contributor
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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

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

Similar topics

5
1811
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 minOccurs="0" maxOccurs="unbounded"> <xsd:any processContents="lax"/> </xsd:choice>
3
2025
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 this message: Below are the results of attempting to parse this document with an SGML parser - I got nothing! So I have no clue what the problem might be. I tried to remove some Javascript but that did not make any difference. So now I have a...
25
12770
by: Ali-R | last post by:
Hi, Is there a parser which parses CSV files? Thanks for your help. Reza
2
3360
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 : this.Btn_Debut.Attributes.Add("onclick","javascript:DatePicker('Selection_Ar chives','Date_Debut')"); So far, no problem with this...
6
21324
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 validation? Thanks -- Paul G Software engineer.
4
1713
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 the output is whats requied. But if Xerces parser is used then no attribute withe name href is created. Can any one suggest what need to to be done.
5
1746
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 field to input an email address. My problem is that the validator won't allow addresses that include a '.' before the @ sign to
3
5091
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 have to enter comments before allowing that page to be submitted. If that cannot be done, what is the best way to do this. What makes it harder is that the questions are being placed on the form from a database dynamically, so we cannot write any...
1
1853
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 className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/>
0
2247
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): PERL5LIB=/Users/Ric/Library/Perl/ ls XML-Parser-2.34/ XML-Parser-2.34.tar
0
9855
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10648
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9426
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7828
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3134
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.