my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes How to validate data in XML file is equal or not to the entered data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to validate data in XML file is equal or not to the entered data" Watch "How to validate data in XML file is equal or not to the entered data" New topic
Author

How to validate data in XML file is equal or not to the entered data

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
i tried to check data in xml file by using Ajax...i tried to enter the value which is already present in xml file...it is not showing any error..can any one help me out..here is the code...waiting for the reply...

function validate()
{
if (document.frm.id.value == "")
{
alert("Enter Package Name");
document.frm.id.focus();
return (false);
}
chkId=/^[WAP_]{4}\d{2}$/;
if (chkId.test(document.frm.id.value))
{}
else
{
alert('Invalid \"Pack Name\" Entry');
return false;
}
if (document.frm.act.value == "")
{
alert("Enter Activation Status");
document.frm.act.focus();
return (false);
}
chkAct=/^[MA]{2}\d{2}$/;
if (chkAct.test(document.frm.act.value))
{}
else
{
alert('Invalid \"Activation Status\" Entry');
return false;
}
if (document.frm.deact.value == "")
{
alert("Enter De-Activation Status");
document.frm.deact.focus();
return (false);
}
chkDeact=/^[MD]{2}\d{2}$/;
if (chkDeact.test(document.frm.deact.value))
{}
else
{
alert('Invalid \"De-Activation Status\" Entry');
return false;
}
if (document.frm.allwpp.selectedIndex < 0)
{
alert("Select one of the \"Allow Post-Paid or Not\" options.");
document.frm.allwpp.focus();
return (false);
}
if (document.frm.allwpp.selectedIndex == 0)
{
alert("Select \"Allow Post-Paid or Not\" option.");
document.frm.allwpp.focus();
return (false);
}
if (document.frm.shrt.value == "")
{
alert("Enter Package Name");
document.frm.shrt.focus();
return (false);
}
return true;
}
function trim(stringToTrim)
{
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function login()
{
if(validate())
{
xmlHttp=GetXmlHttpObject();
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
var id =document.getElementById("id").value;
var url="/xmlgprs/login.xml";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}
function stateChanged()
{
if (req.readyState == 4)
{
if (req.status == 200)
{
parseMsg();
}
else
{
alert("Unable to retrieve");
}
}
}
function parseMsg()
{
response = req.responseXML.documentElement;
var node = response.getElementsByTagName(id);
var chkNode;
var chkNode1 = chkNode.equals(node);
idArray = new Array();
for(var i=0;i<chkNode1;i++)
{
var node1 = node.item(i);
idArray[i] = node1.text;
}
viewElement();
}
function viewElement()
{
alert("valid");
}

Thanks in advance,
madhu.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And please post only the relevant code: most of this is form element validation, which has nothing to do with XML.

And I tell you what: the first time a form makes me submit multiple times for multiple validation errors, I'm off the site, because they don't care enough about me to do it right.

And for goodness sake, refactor :(

And use a JavaScript library--doing Ajax "by hand" is pointless.

And huh?
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
i had done validation by using Ajax..it is working fine..the problem...if i enter another value it is not getting added to xml file...can any one check it and help me out..waiting for the reply...here is the code...

function validate() {
if (document.frm.id.value == "") {
alert("Enter Package Name");
document.frm.id.focus();
return (false);
}
chkId = /^[WAP_]{4}\d{2}$/;
if (chkId.test(document.frm.id.value)) {
} else {
alert('Invalid \"Pack Name\" Entry');
return false;
}
if (document.frm.act.value == "") {
alert("Enter Activation Status");
document.frm.act.focus();
return (false);
}
chkAct = /^[MA]{2}\d{2}$/;
if (chkAct.test(document.frm.act.value)) {
} else {
alert('Invalid \"Activation Status\" Entry');
return false;
}
if (document.frm.deact.value == "") {
alert("Enter De-Activation Status");
document.frm.deact.focus();
return (false);
}
chkDeact = /^[MD]{2}\d{2}$/;
if (chkDeact.test(document.frm.deact.value)) {
} else {
alert('Invalid \"De-Activation Status\" Entry');
return false;
}
if (document.frm.allwpp.selectedIndex < 0) {
alert("Select one of the \"Allow Post-Paid or Not\" options.");
document.frm.allwpp.focus();
return (false);
}
if (document.frm.allwpp.selectedIndex == 0) {
alert("Select \"Allow Post-Paid or Not\" option.");
document.frm.allwpp.focus();
return (false);
}
if (document.frm.shrt.value == "") {
alert("Enter Package Name");
document.frm.shrt.focus();
return (false);
}
return true;
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g, "");
}
var xmlHttp = null;
function login() {
if (validate()) {

try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
var id = document.getElementById("id").value;
var url = "/xmlgprs/login.xml";
url = url + "?id=" + id;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
}
function stateChanged() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
parseMsg();
} else {
alert("Unable to retrieve");
}
}
}
function trim(stringToTrim)
{
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function parseMsg() {
var id = document.getElementById("id").value;
response = xmlHttp.responseXML.documentElement;
var node = response.getElementsByTagName("PACK_NAME");
//Na=Node();
//Na.toString()
// alert(node.length)
//ele=Element()

//ele.nodeValue
for ( var i = 0; i < node.length; i++) {
var node1 = node.item(i);
var childNodes=node1.childNodes;
for ( var j = 0; j < childNodes.length; j++) {
var childNode=childNodes.item(j);
if(childNode.nodeType == Node.TEXT_NODE){
alert(childNode.nodeValue);
if(trim(childNode.nodeValue) == trim(id)){
alert("already Present");
break;
}
}
}

//idArray[i] = node1.text;
}


}


Thanks in advance,
madhu.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.

I'd really rather not have to keep saying that :(
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to validate data in XML file is equal or not to the entered data
 
Similar Threads
object required in java script error
how to check the entered value present in XML file or not
Issue regarding a basic AJAX project
Page section does not update after call of a4j:support in IE 9
ajax not working with jsp