XML Validation..in JSP (Exception Problem)
Hello all,
Below is a .JSP program, which validates an .XML ("validate.xml") file residing in the same container as the JSP. It throws all the possible exception for all possible errors in an XML file(& prints them in a TextArea), but it terminates as soon as it catches the first one.
HOW CAN I MAKE IT CATCH ALL THE POSSIBLE EXCEPTIONS BEFORE TERMINATING??
Please suggest/help. Any help would be thoroughly appreciated. Thanks!
<%@ page session = "false" %>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "javax.xml.parsers.*" %>
<%@ page import = "org.w3c.dom.*" %>
<%@ page import = "org.xml.sax.*" %>
<%@ page import = "org.xml.sax.helpers.*" %>
<%@ page import = "org.apache.xerces.parsers.DOMParser" %>
<%@ page import = "org.apache.xerces.parsers.SAXParser" %>
<HTML>
<HEAD>
</HEAD>
<%
try{
XMLReader parser = new org.apache.xerces.parsers.SAXParser();
DefaultHandler handler= new ProductParser();
parser.setContentHandler(handler);
parser.setErrorHandler(handler);
parser.setFeature ("http://xml.org/sax/features/validation", true);
StringBuffer requestURL = HttpUtils.getRequestURL(request);
URL jspURL = new URL(requestURL.toString());
URL url = new URL(jspURL, "validate.xml");
InputSource is = new InputSource(url.openStream());
parser.parse(is);
catch (SAXException e) {}
%>
<%!
String warn = "";
String err = "";
String fatal = "";
class ProductParser extends DefaultHandler
public void warning (SAXParseException e) throws SAXException // Warning Event Handler
warn = ("Warning: At Line Number " + e.getLineNumber() + " \nError Reason: " + e.getMessage() + "\n");
public void error (SAXParseException e) throws SAXException // Error Event Handler
err = ("Error: At Line Number " + e.getLineNumber() + " \nError Reason: " + e.getMessage() + "\n");
public void fatalError (SAXParseException e) throws SAXException // Fatal Error Event Handler
fatal = ("Fatal Error: At Line Number " + e.getLineNumber() + " \nError Reason: " + e.getMessage() + "\n");
%>
<Body>
The Errors in your XML file are as beloW: <br>
<%=(warn + err + fatal)%>
</Body>
</HTML>
somebody please answer!
Similar Messages
-
hi,
i am trying to validate an xml document against a schema document abnd am getting some strange validation errors. i am using xerces to parse. here are my java classes:-
//---------------------------------------- class Validation-------------------------------------------//
import org.apache.xerces.parsers.DOMParser;
public class Validation {
public static void main(String[] args)
try
DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation","country.xsd");
ErrorChecker errors = new ErrorChecker();
parser.setErrorHandler(errors);
parser.parse("country.xml");
} // end try
catch (Exception e)
System.out.print("Problem parsing the file.");
} // end catch
} // end main
} // end class Validation
//----------------------------------------- class ErrorHandler -----------------------------------------//
import org.xml.sax.*;
public class ErrorChecker implements ErrorHandler
public void warning(SAXParseException exception)
//Ignore warnings
public void error(SAXParseException e)
// A validity error.
System.out.println("Vaidation error: " + e.getMessage());
public void fatalError(SAXParseException e)
// A well-formedness error
System.out.println("Fatal error: " + e.getMessage());
} // end class ErrorChecker
and here is my xml document, called "country.xml":-
<?xml version="1.0"?>
<country
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="country.xsd">
<name>France</name>
<pop>59.7</pop>
</country>
and my schema, called "country.xsd":-
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="pop" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and here are the validation errors that are caught when i try to parse the xml document:-
Vaidation error: Document is invalid: no grammar found.
Vaidation error: Document root element "country", must match DOCTYPE root "null".
could anyone please shed any light on these validation errors? any help much appreciated.
thanks,
ramseyI managed to get it working with the DOM parser. Just in case anyone else has this problem in the future and checks this thread, here is the solution. The problem basically came down to me using
parser.setFeature("http://apache.org/xml/features/validation", true);
instead of
parser.setFeature("http://xml.org/sax/features/validation", true);
When you replace the word "xml" with "sax" in the above it seems to work. So, basically all you need is:-
// enable validation in pipeline
parser.setFeature("http://xml.org/sax/features/validation", true);
// set validator to schema validation
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
And, if you haven't given the schema location inside the XML document itself, then you also need something like the following:-
// this feature needs to be set to true if the schema
// location is NOT hardcoded into the xml document
parser.setProperty("
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "country.xsd");
Thanks for all your help dvohra09, you definitely pointed me in the right direction of looking into the setFeatures() method in more detail. -
Java.lang.Exception error during XML validation by Integration Engine
Hi professionals,
We are trying to use XML validation by the Integration Engine.
Step 1:
We created an appropriate directory structure where we had to store the structure (xsd).
\usr\sap\<system id>\SYS\global\xi\runtime_server\A\B\C\D\E\F
A - validation
B - schema
C - GUID of the SWCV where service interface reside.
D - Repository Namespace where Service Interface is created.
E - Service Interface Name
F - Repository Namespace where Message Type or External Definition is
assigned.
Step 2:
We also changed the references in the xsd to exclude all the subdirectory references.
e.g folder1/folder2/abc.xsd is become abc.xsd only
Step 3:
We stored both xsdu2019s (schema xsd and referenced xsd to the directory created in step 1)
Step 4:
We changed the directory and xsdu2019s permissions to 777 (we chose 777 for testing purpose).
Step 5:
We changed the property schema validation of the sender agreement to Validation by Integration Engine.
Step 6:
We checked RFC destination for AI_VALIDATION_JCOSERVER on AS ABAP and AS Java and establish an successful connection test.
RESTULTS
The result of those steps is an error message in the message monitor of PI with the error tekst:
<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
<SAP:Category>XIServer</SAP:Category>
<SAP:Code area="XML_VALIDATION_INB">CX_XMS_SYSERR_VALIDATION</SAP:Code>
<SAP:P1>java.lang.Exception</SAP:P1>
<SAP:P2 />
<SAP:P3 />
<SAP:P4 />
<SAP:AdditionalText>not used at the moment.</SAP:AdditionalText>
<SAP:Stack>System error occurred during XML validation</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
Please assist in how to solve this issueu2026.
Regards, Sjaak.I would suggest follow Appendix A to know the exact path and since you have one XSD referring other XSD check the steps mentioned in Appendix B .... there seems to be some error in referencing ...Appendix A and B are on page 12 & 13 of this document:
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d06dff94-9913-2b10-6f82-9717d9f83df1?quicklink=index&overridelayout=true
Regards,
Abhishek. -
hi to you all (using WLS 6.1 sp1, win2000)
until today I didn't use the prcompile flag in weblogic.xml and my jsps have
been complied on access -> no problems whatsoever. today I wanted to try the
precompile option and after having added this flag -BANG- no deploying
possible anymore. this is ther log snipplet:
<snip>
####<22.11.2001 14:10:35 CET> <Info> <HTTP> <ws-vep> <myserver> <Application
Manager Thread> <> <> <101047>
<[WebAppServletContext(51375,cyberibisng,/cyberibisng)] checking
html/accountoverview.jsp:>
####<22.11.2001 14:10:36 CET> <Debug> <HTTP> <ws-vep> <myserver>
<Application Manager Thread> <> <> <101158> <Exception thrown while loading
cyberibisng: weblogic.servlet.jsp.JspException: (line 7): Could not parse
deployment descriptor: java.io.IOException: cannot resolve 'webwork' into a
valid tag library>
weblogic.servlet.jsp.JspException: (line 7): Could not parse deployment
descriptor: java.io.IOException: cannot resolve 'webwork' into a valid tag
library
</snip>
and it happens because of this taglib definition:
<%@ taglib uri="webwork" prefix="webwork" %>
why is this happening and doesn't happen when I don't let it precompile??
many thanks in advance!
-paolo
hi to you all (using WLS 6.1 sp1, win2000)
until today I didn't use the prcompile flag in weblogic.xml and my jsps have
been complied on access -> no problems whatsoever. today I wanted to try the
precompile option and after having added this flag -BANG- no deploying
possible anymore. this is ther log snipplet:
<snip>
####<22.11.2001 14:10:35 CET> <Info> <HTTP> <ws-vep> <myserver> <Application
Manager Thread> <> <> <101047>
<[WebAppServletContext(51375,cyberibisng,/cyberibisng)] checking
html/accountoverview.jsp:>
####<22.11.2001 14:10:36 CET> <Debug> <HTTP> <ws-vep> <myserver>
<Application Manager Thread> <> <> <101158> <Exception thrown while loading
cyberibisng: weblogic.servlet.jsp.JspException: (line 7): Could not parse
deployment descriptor: java.io.IOException: cannot resolve 'webwork' into a
valid tag library>
weblogic.servlet.jsp.JspException: (line 7): Could not parse deployment
descriptor: java.io.IOException: cannot resolve 'webwork' into a valid tag
library
</snip>
and it happens because of this taglib definition:
<%@ taglib uri="webwork" prefix="webwork" %>
why is this happening and doesn't happen when I don't let it precompile??
many thanks in advance!
-paolo
-
Not able to run validation using validation.xml & validator-rules.xml
Hello Friends,
I am not able to run validation using validation.xml & validator-rules.xml.
Entire code in running prefectly but no error messages are prompted.
Following is my code:
File Name : struts-config.xml
<struts-config>
<!-- Form Beans Configuration -->
<form-beans>
<form-bean name="searchForm"
type="com.solversa.SearchForm"/>
</form-beans>
<!-- Global Forwards Configuration -->
<global-forwards>
<forward name="search" path="/search.jsp"/>
</global-forwards>
<!-- Action Mappings Configuration -->
<action-mappings>
<action path="/search"
type="com.solversa.SearchAction"
name="searchForm"
scope="request"
validate="true"
input="/search.jsp">
</action>
</action-mappings>
<!-- Message Resources Configuration -->
<message-resources
parameter="ApplicationResources"/>
<!-- Validator Configuration -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
<br> File Name : <b> validation.xml </b>
<form-validation>
<formset>
<form name="searchForm">
<field property="name" depends="minlength">
<arg key="label.search.name" position = "0"/>
<arg1 name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>
<field property="ssNum" depends="mask">
<arg0 key="label.search.ssNum"/>
<var>
<var-name>mask</var-name>
<var-value>^\d{3}-\d{2}-\d{4}$</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
<br> File Name : <b> SearchForm.java </b>
package com.jamesholmes.minihr;
import java.util.List;
import org.apache.struts.validator.ValidatorForm;
public class SearchForm extends ValidatorForm
private String name = null;
private String ssNum = null;
private List results = null;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setSsNum(String ssNum) {
this.ssNum = ssNum;
public String getSsNum() {
return ssNum;
public void setResults(List results) {
this.results = results;
public List getResults() {
return results;
<br> File Name : <b> SearchAction.java </b>
package com.jamesholmes.minihr;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public final class SearchAction extends Action
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
EmployeeSearchService service = new EmployeeSearchService();
ArrayList results;
SearchForm searchForm = (SearchForm) form;
// Perform employee search based on what criteria was entered.
String name = searchForm.getName();
if (name != null && name.trim().length() > 0) {
results = service.searchByName(name);
} else {
results = service.searchBySsNum(searchForm.getSsNum().trim());
// Place search results in SearchForm for access by JSP.
searchForm.setResults(results);
// Forward control to this Action's input page.
return mapping.getInputForward();
<br> File Name : <b> EmployeeSearchService.java </b>
package com.jamesholmes.minihr;
import java.util.ArrayList;
public class EmployeeSearchService
/* Hard-coded sample data. Normally this would come from a real data
source such as a database. */
private static Employee[] employees =
new Employee("Bob Davidson", "123-45-6789"),
new Employee("Mary Williams", "987-65-4321"),
new Employee("Jim Smith", "111-11-1111"),
new Employee("Beverly Harris", "222-22-2222"),
new Employee("Thomas Frank", "333-33-3333"),
new Employee("Jim Davidson", "444-44-4444")
// Search for employees by name.
public ArrayList searchByName(String name) {
ArrayList resultList = new ArrayList();
for (int i = 0; i < employees.length; i++) {
if (employees.getName().toUpperCase().indexOf(name.toUpperCase()) != -1) {
resultList.add(employees[i]);
return resultList;
// Search for employee by social security number.
public ArrayList searchBySsNum(String ssNum) {
ArrayList resultList = new ArrayList();
for (int i = 0; i < employees.length; i++) {
if (employees[i].getSsNum().equals(ssNum)) {
resultList.add(employees[i]);
return resultList;
<br> File Name : <b> Employee.java </b>
package com.solversa;
public class Employee
private String name;
private String ssNum;
public Employee(String name, String ssNum) {
this.name = name;
this.ssNum = ssNum;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setSsNum(String ssNum) {
this.ssNum = ssNum;
public String getSsNum() {
return ssNum;
Pls help me out.
Not able to prompt errors.Hello Friends,
I am not able to run validation using
validation.xml & validator-rules.xml.
Entire code in running prefectly but no error
messages are prompted.
Following is my code:
File Name : struts-config.xml
<struts-config>
<!-- Form Beans Configuration -->
<form-beans>
<form-bean name="searchForm"
type="com.solversa.SearchForm"/>
ans>
<!-- Global Forwards Configuration -->
<global-forwards>
<forward name="search" path="/search.jsp"/>
global-forwards>
<!-- Action Mappings Configuration -->
<action-mappings>
<action path="/search"
type="com.solversa.SearchAction"
name="searchForm"
scope="request"
validate="true"
input="/search.jsp">
tion>
</action-mappings>
<!-- Message Resources Configuration -->
<message-resources
parameter="ApplicationResources"/>
<!-- Validator Configuration -->
<plug-in
className="org.apache.struts.validator.ValidatorPlugI
">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
>
</struts-config>
<br> File Name : <b> validation.xml </b>
<form-validation>
<formset>
<form name="searchForm">
<field property="name" depends="minlength">
<arg key="label.search.name" position = "0"/>
<arg1 name="minlength" key="${var:minlength}"
resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>
<field property="ssNum" depends="mask">
<arg0 key="label.search.ssNum"/>
<var>
<var-name>mask</var-name>
<var-value>^\d{3}-\d{2}-\d{4}$</var-value>
</var>
</field>
/form>
</formset>
form-validation>
<br> File Name : <b> SearchForm.java </b>
package com.jamesholmes.minihr;
import java.util.List;
import org.apache.struts.validator.ValidatorForm;
public class SearchForm extends ValidatorForm
private String name = null;
private String ssNum = null;
private List results = null;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setSsNum(String ssNum) {
this.ssNum = ssNum;
public String getSsNum() {
return ssNum;
public void setResults(List results) {
this.results = results;
public List getResults() {
return results;
<br> File Name : <b> SearchAction.java </b>
package com.jamesholmes.minihr;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public final class SearchAction extends Action
public ActionForward execute(ActionMapping
mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
EmployeeSearchService service = new
EmployeeSearchService();
ArrayList results;
SearchForm searchForm = (SearchForm) form;
// Perform employee search based on what criteria
was entered.
String name = searchForm.getName();
if (name != null && name.trim().length() > 0) {
results = service.searchByName(name);
else {
results =
service.searchBySsNum(searchForm.getSsNum().trim());
// Place search results in SearchForm for access
by JSP.
searchForm.setResults(results);
// Forward control to this Action's input page.
return mapping.getInputForward();
<br> File Name : <b> EmployeeSearchService.java </b>
package com.jamesholmes.minihr;
import java.util.ArrayList;
public class EmployeeSearchService
/* Hard-coded sample data. Normally this would come
from a real data
source such as a database. */
ivate static Employee[] employees =
new Employee("Bob Davidson", "123-45-6789"),
new Employee("Mary Williams", "987-65-4321"),
new Employee("Jim Smith", "111-11-1111"),
new Employee("Beverly Harris", "222-22-2222"),
new Employee("Thomas Frank", "333-33-3333"),
new Employee("Jim Davidson", "444-44-4444")
// Search for employees by name.
public ArrayList searchByName(String name) {
ArrayList resultList = new ArrayList();
for (int i = 0; i < employees.length; i++) {
if
(employees.getName().toUpperCase().indexOf(name.toU
pperCase()) != -1) {
resultList.add(employees[i]);
return resultList;
// Search for employee by social security number.
public ArrayList searchBySsNum(String ssNum) {
ArrayList resultList = new ArrayList();
for (int i = 0; i < employees.length; i++) {
if (employees[i].getSsNum().equals(ssNum)) {
resultList.add(employees[i]);
return resultList;
<br> File Name : <b> Employee.java </b>
package com.solversa;
public class Employee
private String name;
private String ssNum;
public Employee(String name, String ssNum) {
this.name = name;
this.ssNum = ssNum;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setSsNum(String ssNum) {
this.ssNum = ssNum;
public String getSsNum() {
return ssNum;
Pls help me out.
Not able to prompt errors.
Hi,
Your error message are not displaying because u does not made Message-Resoucrce property file (Resource Bundle) when you make it .
give it entry in
struts-config.xml
<message-resources parameter="ApplicationResources" />
and
define key and corresponding error message to key in this ApplicationResources i.e
#Error Resources
label.search.ssNum=Plz Enter correct ssNum -
XML validation using javax.xml.validation
Hello,
I am trying to validate some xml against my xsd.
Here is my xml:
<host>
<status>Unknown</status>
</host>Here is my xsd:
<?xml version="1.0"?>
<xsd:schema targetNamespace="blah"
xmlns:tns="blah"
xmlns:xsd="blah">
<xsd:simpleType name="Status">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Unknown"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="host">
<xsd:complexType>
<xsd:all>
<xsd:element name="status" type="tns:Status"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>My test code is:
try
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File("test.xml"));
// Create a SchemaFactory capable of understanding WXS schemas.
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Load a WXS schema, represented by a Schema instance.
StreamSource schemaFile = new StreamSource(new File("schema.xsd"));
Schema schema = factory.newSchema(schemaFile);
// Create a Validator object, which can be used to validate the document
Validator validator = schema.newValidator();
// Validate the DOM tree.
validator.validate(new DOMSource(document));
catch(Exception e)
fail("XML validation failed: " + e.getMessage());
}I get the following error:
ERROR: 'cvc-elt.1: Cannot find the declaration of element 'host'.'
If i replace "type=tns:Status' in the "status" element with just "type=string", it works fine.
Does anyone have any idea what the problem is?
Thank you,
DavidTo daft_davy:
1. Your XSD document is invalid: the xmlns attribute of schema documents must always have the following value: "http://www.w3.org/2001/XMLSchema"
All other values will result in the following validation error:
org.xml.sax.SAXParseException: s4s-elt-schema-ns: The namespace of element 'schema' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
Your XSD should look like this:
<?xml version="1.0"?>
<xsd:schema targetNamespace="blah" xmlns:tns="blah" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="Status">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Unknown"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="host">
<xsd:complexType>
<xsd:all>
<xsd:element name="status" type="tns:Status"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>2. Your XML document does not match the XSD schema (even if you use the one above) for the following reasons:
a) The root element of the XML document must be associated with the namespace defined by the targetNamespace attribute of the schema.
b) The "blah" namespace at the element <status> in the XML document has to be undeclared because there is no namespace declaration to this element in the schema document either. There are to ways to do this:
<host xmlns="blah">
<status xmlns="">Unknown</status>
</host>or:
<xxx:host xmlns:xxx="blah">
<status>Unknown</status>
</xxx:host>
To watertownjordan:
The namespace URI can be virtually any string, so you don't need to specify a valid URI to define a namespace. -
Inbound XML validation failed against schema
Hi Experts,
we are getting mapping exception at the time of Inbound XML validation but in the trace it is not displaying
like which fields are not validating.
I have gone through the Interface mapping in that we are using 2 mapping programs one is imported archives(java mapping) for validation
and another one is for Messaging mapping.we are getting the problem at the time of validation itself,
i have navigated by double clicking on the imported archive mapping program it is taken into another page
where we will get the archive programs.we have soo many xsd files and its path, and one .java file and class file
for validatting the xsd files. up to now everything is fine.
please find the remaining question in the below postCONTINUATION QUESTION FOR THE ABOVE
If i click on the xsd files it is displaying the complete schema structure, but in the case of 2 xsd files(those are using in one
interface where we are getting validation error)it is displaying the error like "cannot display file com/AAA/BBB/java/CCC/xi/bc/validator/xsds/<filename.xsd> unable to determine code".as per my assumption the xsd file
is not present in that perticular path, if so how can i put these xsd files into the path specified? how can i get that folders to nagvigate into that path? And also i am not able to download the xsd file from the external defination, is it work if i copy the file into note pad and by changing the extension as .xsd ?
We are using PI7.0, give me an idea how to resolve the issue
Thanks in Advance -
STRUTS: client-side validation in jsp using DynaValidatorForm
I am supposed to work on struts on as project and it is like learning a crash course and work the next day.
In Struts 1.1 enviroment, I am using DynaValidatorForm to create a bean form and then perform validation.
1. I write a DynaValidatorForm definition in struts-config.xml
2. I write xml for action so that when /getQuotes.do in invoked by a jsp form, the form data is put into the QuoteDetailsBean.
3. add the plugin script for ValidatorPlugIn
xml fragment from struts-config:
//form bean
<form-beans>
<form-bean name="QuoteDetailsBean" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="forename" type="java.lang.String"/>
<form-property name="surname" type="java.lang.String"/>
<form-bean>
</form-beans>
<action
path="/getQuotes"
type="com.kainos.quickquotes.struts.QQGetQuotesAction"
validate="true"
name="QuoteDetailsBean"
input="/userform1.do"
parameter="save"
scope="session">
<forward name="success" path="/pages/jsp/result.jsp"/>
<forward name="back" path="/userform1.do"/>
</action>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>Now I write a validation code for getQuotes.do. note that I can write the validation code with
<form name="QuoteDetailsBean"> but this form bean is shared by many jsp, so i am using the name of the action
(getQuotes) as the name of the form in the validation.xml.
So far this looks okay, as I am going by some example.
xml fragment from validation.xml:
<formset>
<form name="/getQuotes">
<field property="forename" depends="required,minlength">
<arg0 key="QuoteDetailsBean.forename" />
<arg1 name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>2</var-value>
</var>
</field>
<field property="surname" depends="required,minlength">
<arg0 key="QuoteDetailsBean.surname" />
<arg1 name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>2</var-value>
</var>
</field>
</formset>Now I write the JSP. I use the <html:javascript> tag to allow front-end validation based on the xml in validation.xml.
The jsp code:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html locale="true">
<head>
<title><bean:message key="welcome.title"/></title>
<html:base/>
<html:javascript formName="/getQuotes"
method="validateForm"
dynamicJavascript="true"
staticJavascript="false"
cdata="false" />
</head>
<body bgcolor="#FFCC9F">
<html:errors />
<html:form action="getQuotes.do" onsubmit="return validateForm(this);" >
Forename:</td> <td>���<html:text property="forename"/></td></tr>
<tr> <td>Surname:</td> <td>���<html:text property="surname"/></td></tr>
<html:submit value="Quotes" /></td></tr>
</html:form>
</body>
</html:html>Does this looks okay. I wrote so far based on some tutorials n help online.
Now when I open the JSP and then do a submit, there is no validation (I tried by submitting with empty forename and surname. I mean i could invoke the action class and the invoke class
redirects(forwards) to the appropriate path. so the code works fine except validation is not done
Q1. So what should i do more to get client-side validation?
What actually happens in client-side validation? does a pop up alert appears?
nothing happens so far in my case.
Q2. What should I do more for server side validation. Since the form is incomplete, what happens?
I thought the same form returns and the error messages are printed in the jsp page since i have the <html:errors />
tag just below the <body> tag.
The action class is pretty simple so far:
public class QQGetQuotesAction extends Action {
public QQGetQuotesAction(){
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
DynaValidatorForm dynaform = (DynaValidatorForm)form;
System.out.println("forename:"+dynaform.get("forename");
System.out.println("surname:"+dynaform.get("surname");
return forward=mapping.findForward("back");
}Please help me out. I think I am missing something which i need to do
thanks
TanveerI think the validations are to be declared on the form
name and not the action path.
Your formName is QuoteDetailsBean but your are using
the action path(/getQuotes) both in the validation
rules and the jsp tags. Use the formName on both the
places.
Also your html:javascript tag will not generate the
static javascript to validate the fields. For this you
will have to add code like below.
<html:javascript dynamicJavascript="false"
staticJavascript="true"/>
Other options is to set the attribute
staticJavascript="true" in your html:javascript tag.
Hope it helps.hi
staticJavascript="true" did the trick. :)
I think the validations are to be declared on the form name and not the action path.It is not necessary. You can declare the validation on the action class. This is essential if a form bean is shared by several JSPs having its own action class. This is as per as I read in a tutorial and it works. -
Unwanted stack trace in weblogic.log for thrown JSP Exceptions
We are throwing a JSP exception within a custom tag when data validation
errors occur; the errorPage for the JSP page is then invoked to show the
appropriate errors. However, in the weblogic.log, a stack trace is shown
indicating the exception (example below). We do not want this stack track
shown unless there is a real "error" in our system vs. invoking the
errorPage to show "application" errors. Is there any way to supress this,
as we are not explicitly causing this to happen. It appears to be a
weblogic feature. This causes us problems in finding true system errors
that might be occurring due to these non-problems showing up in the
weblogic.log.
Thanks for the help.
John Bauer
Wed Dec 20 15:34:49 EST 2000:<E> <ServletContext-General> exception raised
on '/test/test.jsp'
javax.servlet.ServletException: runtime failure in custom tag 'testtag'
at jsp_servlet._test._test._jspService(_test.java:89)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:124)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
l.java:
60)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
l.java:
07)
at
weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
Manager
java:251)
at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:369)
at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled
Code)
The design of the data entry pages is such that the error page is the same
page as the data entry page, and a validation JSP tag validates the data and
if it finds a problem, it will set some variables and throw a JSP exception
to redisplay the page. Unfortunately, we are forced to live with this
design. Are you aware of any mechanism to suppress the automatic logging of
thrown JSP exceptions in the weblogic log?
Thanks,
JDB
Cameron Purdy <[email protected]> wrote in message
news:[email protected]...
> Exception handling for custom tags is very poorly handled right now. For
> one thing, WL hides the actual exception.
>
> However, the way that you are doing this seems very odd. The error page
is
> for server errors, not user typos.
>
> Peace,
>
> --
> Cameron Purdy
> Tangosol, Inc.
> http://www.tangosol.com
> +1.617.623.5782
> WebLogic Consulting Available
>
>
> "John Bauer" <[email protected]> wrote in message
> news:[email protected]...
> > We are throwing a JSP exception within a custom tag when data validation
> > errors occur; the errorPage for the JSP page is then invoked to show the
> > appropriate errors. However, in the weblogic.log, a stack trace is
shown
> > indicating the exception (example below). We do not want this stack
track
> > shown unless there is a real "error" in our system vs. invoking the
> > errorPage to show "application" errors. Is there any way to supress
this,
> > as we are not explicitly causing this to happen. It appears to be a
> > weblogic feature. This causes us problems in finding true system errors
> > that might be occurring due to these non-problems showing up in the
> > weblogic.log.
> >
> > Thanks for the help.
> > John Bauer
> >
> > Wed Dec 20 15:34:49 EST 2000:<E> <ServletContext-General> exception
raised
> > on '/test/test.jsp'
> > javax.servlet.ServletException: runtime failure in custom tag 'testtag'
> > at jsp_servlet._test._test._jspService(_test.java:89)
> > at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
> > at
> >
>
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
> > :124)
> > at
> >
>
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
> > l.java:
> > 60)
> > at
> >
>
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
> > l.java:
> > 07)
> > at
> >
>
weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
> > Manager
> > java:251)
> > at
> >
>
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:369)
> > at
> > weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
> > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java,
Compiled
> > Code)
> >
> >
>
>
-
I'm trying to write an SVG parser using Xerces. The problem is that when the SVG file contains the doctype tag <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">my program throws the following exception:
java.net.UnknownHostException: www.w3.org
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
etc.If I remove <!DOCTYPE> tag, it works fine. According to what I read here, it's necessary to disable XML validation. The Xerces API documentation says that there is a method setValidation() in org.apache.xerces.framework.XMLParser but I can't locate it. Moreover, I don't see any org.apache.xerces.framework package in Xerces supplied with NetBeans 5.0 nor in Xerces 2.8.0 downloaded from apache.org (the XMLParser class available to me is located in org.apache.xerces.parsers).
My question is simple:
How to disable XML validation if the setValidation() method is not avaliable
OR
how to make the setValidation method available to my program?
I'm really confused :(
Here is the code:
package svgviewer;
import java.io.File;
import org.w3c.dom.*;
import org.w3c.dom.traversal.*;
import org.apache.xerces.parsers.*;
public class SVGFileParser {
public void parse(String filename) throws Exception {
File file = new File(filename);
DOMParser parser = new DOMParser();
parser.parse(file.toURL().toString()); //exception is thrown if doctype tag is present in the svg fileYou're solving the wrong problem here. Turning off validation won't help, because DTDs don't only do validation. Even non-validating parsers have to read the DTD in case it contains entity definitions, for example.
If you want to stop the parser from looking for the DTD then you write a EntityResolver and apply it to the parser. The EntityResolver should be just like the one in the example in the API docs except it should return new InputSource(new StringReader("")). -
Re: [iPlanet-JATO] sp3 jsp compiler problem
Weiguo,
First, Matt is correct, the regular expression tool is perfect for general text
substitution situations, and as a completely independent tool its use is not
restricted to migration situations (or file types for that matter).
Second, I sympathize with the unfortunate trouble you are experiencing due to
Jasper's (perhaps more strict) compilation, but in what way did the iMT
automated translation contribute to these inconsistencies that you cited?
1. Changed the case of the tag attribute to be the same as what's
defined in tld.
example: changed OnClick to onClick
The iMT does not generate any OnClick or onClick clauses per se. In a
translation situation, the only way "OnClick" would have been introduced was if
it had been part of the pre-existing project's "extraHTML" (which was written
by the original customer and just passed through unchanged by the iMT) or if it
was added manually by the post-migration developer.
2. Removed attributes which are not defined in tld.
example: escape attribute only defined in three tags
but in some pages, it's used although it's not defined as an
attribute
of certain tags. The jasper compiler doesn't like it.Can you give soem examples? Is there a definite pattern? Again, this might be
similar to the OnClick situation described above?
3. In an end tag, there can't be any space.
example: </content > doesn't work. </content> works.
Again, the content tag would never have been generated by the iMT. There was no
equivalent in the NetDynamics world, so any content tags in your code must have
been introduced by your developers manually. Its a shame that jasper is so
particular, but the iMT could not help you out here even if we wanted to. The
constants that are used by the iMT are defined in
com.iplanet.moko.jsp.convert.JspConversionConstants. From what I can see, the
only situation of a closing tag with any space in it is
public static final String CLOSE_EMPTY_ELEMENT = " />";
But that should not cause the type of problem you are referring to.
Mike
----- Original Message -----
From: Matthew Stevens
Sent: Thursday, September 06, 2001 10:16 AM
Subject: RE: [iPlanet-JATO] sp3 jsp compiler problem
Weiguo,
Others will chime in for sure...I would highly recommend the Regex Tool from
the iMT 1.1.1 for tackling this type of problem. Mike, Todd and myself have
posted to the group (even recently) on directions and advantages of creating
your own RULES (rules file) in XML for arbitary batch processing of source.
matt
-----Original Message-----
From: weiguo.wang@b...
[mailto:<a href="/group/SunONE-JATO/post?protectID=125056020108194190033029175101192165174144234026000079108238073194105057099246073154180137239239223019162">weiguo.wang@b...</a>]
Sent: Thursday, September 06, 2001 12:25 PM
Subject: [iPlanet-JATO] sp3 jsp compiler problem
Matt/Mike/Todd,
We are trying to migrate to sp3 right now, but have had a lot of
issues with the new jasper compiler.
The following workaround has been employed to solve the issues:
1. Changed the case of the tag attribute to be the same as what's
defined in tld.
example: changed OnClick to onClick
2. Removed attributes which are not defined in tld.
example: escape attribute only defined in three tags
but in some pages, it's used although it's not defined as an
attribute
of certain tags. The jasper compiler doesn't like it.
3. In an end tag, there can't be any space.
example: </content > doesn't work. </content> works.
As I see it, we have two options to go about solving this problem:
1. Write a script which will iterate through all the jsp files and
call jspc on them. Fix the errors manually when jspc fails. Jspc will
flag the line number where an error occurs.
2. Write a utility which scans the jsp files and fix the errors when
they are encountered. We should define what's an error and how to
correct it. It's best if we combine this with solution 1 since we
might miss an error condition.
Actually, there might be another option, which is seeking help from
you guys since you have better understanding of JATO and iAS. Can you
do anything to help us?
We would be happy to hear your thoughts.
At last, I would like to suggest modifying the moko tool so that
these rules are enforced and the generated JSPs work with the new
compiler. This is for the benefit of any new migration projects.
Thanks a lot.
Weiguo
[email protected]
Choose from 1000s of job listings!
[email protected]
[Non-text portions of this message have been removed]Thanks a lot Matt and Mike for your prompt replies.
I agree completely that iMT doesn't introduce the inconsistencies.
About the three cases I mentioned, the third one happens only in
manually created JSPs. So it has nothing to do with iMT. The first
two are mainly due to the existing HTML code, as you rightly pointed
out.
The reason I made the suggestion is since we know that case 1 and 2
won't pass the japser compiler in sp3, we have to do something about
it. The best place to do this, in my mind, is iMT. Of course, there
might be some twists that make it impossible or difficult to do this
kind of case manipulation or attribute discard.
Weiguo
--- In iPlanet-JATO@y..., "Mike Frisino" <Michael.Frisino@S...> wrote:
Weiguo,
First, Matt is correct, the regular expression tool is perfect for general text substitution situations, and as a completely independent
tool its use is not restricted to migration situations (or file types
for that matter).
>
Second, I sympathize with the unfortunate trouble you are experiencing due to Jasper's (perhaps more strict) compilation, but
in what way did the iMT automated translation contribute to these
inconsistencies that you cited?
>
1. Changed the case of the tag attribute to be the same as what's
defined in tld.
example: changed OnClick to onClick
The iMT does not generate any OnClick or onClick clauses per se. In a translation situation, the only way "OnClick" would have been
introduced was if it had been part of the pre-existing
project's "extraHTML" (which was written by the original customer and
just passed through unchanged by the iMT) or if it was added manually
by the post-migration developer.
>
2. Removed attributes which are not defined in tld.
example: escape attribute only defined in three tags
but in some pages, it's used although it's not defined as an
attribute
of certain tags. The jasper compiler doesn't like it.Can you give soem examples? Is there a definite pattern? Again, this might be similar to the OnClick situation described above?
>
>
3. In an end tag, there can't be any space.
example: </content > doesn't work. </content> works.
Again, the content tag would never have been generated by the iMT. There was no equivalent in the NetDynamics world, so any content tags
in your code must have been introduced by your developers manually.
Its a shame that jasper is so particular, but the iMT could not help
you out here even if we wanted to. The constants that are used by the
iMT are defined in
com.iplanet.moko.jsp.convert.JspConversionConstants. From what I can
see, the only situation of a closing tag with any space in it is
public static final String CLOSE_EMPTY_ELEMENT = " />";
But that should not cause the type of problem you are referring to.
Mike
----- Original Message -----
From: Matthew Stevens
Sent: Thursday, September 06, 2001 10:16 AM
Subject: RE: [iPlanet-JATO] sp3 jsp compiler problem
Weiguo,
Others will chime in for sure...I would highly recommend the Regex Tool from
the iMT 1.1.1 for tackling this type of problem. Mike, Todd and myself have
posted to the group (even recently) on directions and advantages of creating
your own RULES (rules file) in XML for arbitary batch processing of source.
>
matt
-----Original Message-----
From: weiguo.wang@b...
[mailto:<a href="/group/SunONE-JATO/post?protectID=125056020108194190033029175101192165174048139046">weiguo.wang@b...</a>]
Sent: Thursday, September 06, 2001 12:25 PM
Subject: [iPlanet-JATO] sp3 jsp compiler problem
Matt/Mike/Todd,
We are trying to migrate to sp3 right now, but have had a lot of
issues with the new jasper compiler.
The following workaround has been employed to solve the issues:
1. Changed the case of the tag attribute to be the same as
what's
defined in tld.
example: changed OnClick to onClick
2. Removed attributes which are not defined in tld.
example: escape attribute only defined in three tags
but in some pages, it's used although it's not defined as an
attribute
of certain tags. The jasper compiler doesn't like it.
3. In an end tag, there can't be any space.
example: </content > doesn't work. </content> works.
As I see it, we have two options to go about solving this problem:
>>
1. Write a script which will iterate through all the jsp files and
call jspc on them. Fix the errors manually when jspc fails. Jspc will
flag the line number where an error occurs.
2. Write a utility which scans the jsp files and fix the errors when
they are encountered. We should define what's an error and how to
correct it. It's best if we combine this with solution 1 since we
might miss an error condition.
Actually, there might be another option, which is seeking help from
you guys since you have better understanding of JATO and iAS. Can you
do anything to help us?
We would be happy to hear your thoughts.
At last, I would like to suggest modifying the moko tool so that
these rules are enforced and the generated JSPs work with the new
compiler. This is for the benefit of any new migration projects.
Thanks a lot.
Weiguo
[email protected]
Choose from 1000s of job listings!
[email protected]
Service.
>
>
>
[Non-text portions of this message have been removed] -
How to read an attribute of an xml tag in jsp.
hi guys,
This is murali krishna. i have a small problem,
i have one xml file (books.xml)
<?xml version="1.0" encoding="iso-8859-1"?>
<library>
<book id="1">
<name>Head First Java, 2nd Edition</name>
<author>Kathy Sierra and Bert Bates</author>
<publication-date>09-Feb-2005</publication-date>
</book>
<book id="2">
<name>Effective Java</name>
<author>Joshua Bloch</author>
<publication-date>28-May-2008</publication-date>
</book>
<book id="3">
<name>Java How to Program, 7th Edition</name>
<author>Harvey M. Deitel and Paul J. Deitel</author>
<publication-date>6-Jan-2007</publication-date>
</book>
</library>
I tried to read this xml file in jsp as shown below
<%@ page language="java" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="javax.xml.parsers.DocumentBuilder" %>
<%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
<%
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db =dbf.newDocumentBuilder();
Document doc=db.parse("c:\\books.xml");
NodeList nl = doc.getElementsByTagName("book");
%>
<html>
<head>
<title>How to read XML file in JAVA</title>
</head>
<body>
<%
for(int i=0;i<nl.getLength();i++)
NodeList nameNlc= doc.getElementsByTagName("name");
Element nameElements=(Element)nameNlc.item(i);
String nameTagValue=nameElements.getChildNodes().item(0).getNodeValue();
NodeList authorNlc= doc.getElementsByTagName("author");
Element authorElements=(Element)authorNlc.item(i);
String authorTagValue=authorElements.getChildNodes().item(0).getNodeValue();
NodeList dateNlc= doc.getElementsByTagName("publication-date");
Element dateElements=(Element)dateNlc.item(i);
String dateTagValue=dateElements.getChildNodes().item(0).getNodeValue();
out.println("name :"+nameTagValue+"<br>");
out.println("author :"+authorTagValue+"<br>");
out.println("publication-date :"+dateTagValue+"<br><br>");
%>
</body>
</html>
so, my problem is I was unable to read the attribute of the tag book , that is "id".
can any one tell me how to read this "id" attribute.
Murali Krishna
[email protected]hi,
U r retriving the elements by tag name.So it just chks the tag name ie.<book> & gives u array of elements.But u need retrive d attribute of <book> tag itself.
=Solution =====
Add one more statement ----> var[]= doc.getElementsByName("book");
Now u hav book elements as an array & can retrive id in for loop
for(var; var.length;var++)
doc.element[var].id.value -
XML Validation - How to raise an alert
Hi PI Experts,
I enabled XML validation at "Validtion by Adapetr Engine". Its working fine. But how to integrate XML validation error with Alert Monitoring. Please advise.
Here below the error from Audit log:
2010-03-18 18:33:13 Information The application tries to send an XI message asynchronously using connection File_http://sap.com/xi/XI/System.
2010-03-18 18:33:13 Information Backward validation is enabled
2010-03-18 18:33:13 Error Unable to validate the message with message ID b01d356e-1801-4b93-29fb-9ed84b25c6a3
2010-03-18 18:33:13 Error Returning to application. Exception: com.sap.engine.interfaces.messaging.api.exception.MessageFormatException: cvc-enumeration-valid: Value '11' is not facet-valid with respect to enumeration '[1, 2, 3, 4, 5, 6, 7]'. It must be a value from the enumeration. at line 15, column 34
2010-03-18 18:33:13 Error MP: exception caught with cause com.sap.engine.interfaces.messaging.api.exception.MessageFormatException: cvc-enumeration-valid: Value '11' is not facet-valid with respect to enumeration '[1, 2, 3, 4, 5, 6, 7]'. It must be a value from the enumeration. at line 15, column 34
2010-03-18 18:33:13 Error File processing failed with com.sap.engine.interfaces.messaging.api.exception.MessageFormatException: cvc-enumeration-valid: Value '11' is not facet-valid with respect to enumeration '[1, 2, 3, 4, 5, 6, 7]'. It must be a value from the enumeration. at line 15, column 34
Thanks...
Ravi KanakamHi Ravi,
Are you getting other adapter engine alerts? Or only you are not getting xml validation ones? Also take a look at this:
/people/michal.krawczyk2/blog/2005/09/09/xi-alerts--troubleshooting-guide
Regards,
---Satish -
Dear Experts,
after I finally managed to configure the XML Validation, we're facing the next problem:
The payload of the XML files looks like that:
Abcdef#ABCDEF
AbcDef#123
<?xml version="1.0" encoding="UTF-8"?><Document xmlns.....
as you can see, there's a header which is necessary. The XML Validation works fine if the header is removed manually for testing. If the header is not removed, the validation is not possible ("Content is not allowed in prolog.")
Is it possible to realise the validation WITH that header? Can I tell SAP PI to ignore the header? Or make any changes to the XSD file?
Thanks alot!Hi Armin,
Armin Kern wrote:
> After leaving SAP PI, those 2 lines have to be in that exact place (before the XML part) for further processing. Just deleting it wouldn't be enought. Does the complex design you mentioned complay with this requirement?
You can put it into the message instead of deleting. And rebuild the "header" in the second step. So you can fullfill the requirement. As mentioned before: The design is complex, this will lead later on to problems. Any change will be difficult, as another developer had to read a long documentation.
An alternative would be to do all with one interface mapping (without validation):
1. ABAP / Java mapping deleting the "header" (put it to memory)
2. Messges Mapping 1:1 each field (will fail in case of wrong format and act as validator)
3. ABAP / Java mapping restoring the header
4. Alert will be raised in case of an error (to get the result of the validation)
Armin Kern wrote:
> I also thought about splitting the message, deleting those 2 rows in one of the messages, sending this one message to PI again, validate it and if it is correct, send the second message (without mapping) to the final destination. No idea if that is possible at all..
As well possible. You would need a virtual receiver for the first message, which is sending back a response. For example a servlett, a proxy or a RFC module. In that design you put some logic to the sender, what is actually not bad. But if you do so, why you dont validate there as well (for example with Java)? It would make your design much easier..
Regards,
Udo -
Since there is no XML validation currently in the Flex/Flash framework, I've decided to start a class that parses a string in an effort to validate the markup, returning whether the XML is valid. I have a need for it in my non-server based application, and have read in numerous places where there is desire for it as well. I have built the class far enough to get the ball rollin', but figure it should be :
A) available to the community
B) able to be improved upon by the community
If you improve upon the code, please post your work here so everyone can benefit.
Here is the source code :
XML Validator : v0.2 - last edit by Justin Myers | J2 CREATIVE MEDIA DESIGN
NOTES:
Parser is a bit weak and needs work.
Still need to :
- Make sure tags are ended properly
- Make sure there is space between tag name and attribute
Parser currently handles :
- Making sure there is no space between tags (with exception to white space)
- Making sure that attributes open and close properly
- Making sure there is proper space after an attribute or that it is immediately followed with the tag closing
package community.classes.parsers
public class XMLValidator
public function XMLValidator()
public static function validate(str:String , ignoreWhiteSpace:Boolean = true):Boolean
// validation defaults to true (innocent til proven guilty)
var valid:Boolean = true;
// minimum char length to be valid XML
if (str.length < 4)
valid = false;
var withinTag:Boolean;
var withinAttribute:Boolean;
var tags:Array = [];
var tag:String;
for (var i:uint = 0 ; i < str.length ; i++)
var char:String = str.charAt(i);
// if we are closing a tag
if (char == ">")
// invalid if we never opened a tag, or if we never closed the last attribute
if (!withinTag || withinAttribute)
valid = false;
break;
else
withinTag = false;
tags.push(tag);
// invalid if last character is not a closing tag
else if (i == str.length - 1)
valid = false;
break;
// if we are entering a tag
else if (char == "<")
// invalid if we haven't closed the last tag
if (withinTag)
valid = false;
break;
else
withinTag = true;
tag = "";
// all other characters
else
if ((char != " " || char != "\n") || ((char == " " || char == "\n") && !ignoreWhiteSpace) )
// invalid if there are any characters between tags
if (!withinTag)
valid = false;
break;
else
if (char == "\"")
// entering attribute
if (!withinAttribute)
// invalid if = does not preclude ", or there is space before =
if (str.charAt(i-1) != "=" || str.charAt(i-2) == " ")
valid = false;
break;
else
withinAttribute = true;
// exiting attribute
961190 wrote:
so whats the best way to store Rules?
How to get the data validated with those rules given the source data is in a xml file
The "integrity rules"?
Since they have to be ececutable code I'd suggest Java classes...
How to get the data validated with those rules given the source data is in a xml file
as @hsc71 wrote, that each XML element select the rules this particular element should pass and run each rule with the current element as parameter.
This meight be easiser in the Rules have a common interface like
interface Rule{
public boolean isPassedBy(XmlElement theCurrentElement, XmlElement theRootElement);
You could use the ServiceRegistry class from the JVM to fetch the known rules, so that you can add new ones with minimum effort.
bye
TPD
Maybe you are looking for
-
Whenever I tried to scroll through the Fonts in the Character Panel, it moves the selection to the first font in the character panel. Is it because of the Numerous number of fonts in my System. Also certain characters in my native language dont appea
-
I have a MacBookPro with OS X Version 10.7.5 and would like to open PDFs in Firefox 16.0.2. I have tried adding Google Docs Viewer, PDF Viewer 3.0.0.2 and PDF viewer 0.6.39 Can't get any of them to work Ideas? ClearKase
-
Where can I buy a secondary battery for my T430?
I have not been able to find any batteries for the T430 on lenovo's site. I'd like to have a second as a backup. Solved! Go to Solution.
-
JDeveloper & web services problems
I've recently installed jdeveloper onto winXP pro from the jdev9i_902.zip download and installed to D:\jdeveloper. Following the instructions I also installed JDK1.3 to D:\jdk1.3.1_04. I ran the setup for oc4j. The problem I have is that when I follo
-
Announcing Oracle Portal Studio
Oracle Portal Studio is a hosted service that provides you a platform for registering and testing your web providers, without needing your own Oracle Portal instance! Try it out at http://portalstudio.oracle.com/