cancel
Showing results for 
Search instead for 
Did you mean: 

Getting ParserException: </ expected(:main:, row:1, col:101)

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

I am using a java code for schema validation of input XI message.

Java code:

-


import java.io.FileInputStream;

import java.io.FileOutputStream;

import com.sap.aii.mapping.api.StreamTransformation;

import java.io.*;

import java.util.Map;

import javax.xml.parsers.*;

import org.xml.sax.*;

import org.xml.sax.helpers.*;

public class P2PValidation extends DefaultHandler implements StreamTransformation{

private Map map;

private OutputStream out;

//Constants when using XML Schema for SAX parsing.

static final String JAXP_SCHEMA_LANGUAGE =

"http://java.sun.com/xml/jaxp/properties/schemaLanguage";

static final String W3C_XML_SCHEMA =

"http://www.w3.org/2001/XMLSchema";

static final String JAXP_SCHEMA_SOURCE =

"http://java.sun.com/xml/jaxp/properties/schemaSource";

public void setParameter (Map param){

map = param;

}

public void execute (InputStream in, OutputStream out)

throws com.sap.aii.mapping.api.StreamTransformationException {

DefaultHandler handler = this;

SAXParserFactory factory = SAXParserFactory.newInstance();

//Obtain an object of class javax.xml.parsers.SAXParser,

factory.setNamespaceAware(true);

factory.setValidating(true);

try {

SAXParser saxParser = factory.newSAXParser();

// Setup the schema file

saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

saxParser.setProperty(JAXP_SCHEMA_SOURCE, new File("IOReqMsgSchema.xsd"));

//System.out.println("Parsing");

this.out = out;

saxParser.parse(in, handler);

}

catch (Exception t){

t.printStackTrace();

}

}

private void write (String s) throws SAXException{

try{

out.write(s.getBytes()); out.flush();

}

catch (IOException e){

throw new SAXException("I/O error", e);

}

}

public void startDocument () throws SAXException{

write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

write("<ns0:ValidInternalOrder xmlns:ns0=\"http://www.xyz.com/Gopal\">");

}

public void endDocument () throws SAXException {

write("</ns0:ValidInternalOrder>");

try { out.flush();

}

catch (IOException e) {

throw new SAXException("I/O error", e);

}

}

public void startElement (String namespaceURI, String sName, String qName, Attributes attrs)

throws SAXException {

System.out.println("sName="sName" qName="+sName);

if(sName.equals(qName))

write("<"sName">");

}

public void endElement (String namespaceURI, String sName, String qName) throws SAXException {

if(sName.equals(qName))

write("</"sName">");

}

public void characters (char buf[], int offset, int len)

throws SAXException {

String s = new String(buf, offset, len);

write (s);

}

public void error(SAXParseException se) throws SAXException {

throw se;

}

}

Input XML:

-


<?xml version="1.0" encoding="UTF-8"?>

<ns0:InternalOrder_request xmlns:ns0="http://www.xyz.com/Gopal">

<ORDER>TEST101</ORDER>

<ORDER_TYPE>XYZ</ORDER_TYPE>

<ORDER_NAME>TEST</ORDER_NAME>

<CO_AREA>ABC</CO_AREA>

<CCTR_POSTED>56345</CCTR_POSTED>

<CURRENCY>INR</CURRENCY>

<PERSON_RESP>SAMUAL</PERSON_RESP>

</ns0:InternalOrder_request>

Input xsd:

-


<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.xyz.com/Gopal" targetNamespace="http://www.xyz.com/Gopal">

<xsd:element name="InternalOrder_request" type="InternalOrder" />

<xsd:complexType name="InternalOrder">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

96f86070e91411dc9c0d0012799ec115

</xsd:appinfo>

</xsd:annotation>

<xsd:sequence>

<xsd:element name="ORDER">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce800896811dca23200c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

Order

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="1" />

<xsd:maxLength value="12" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

<xsd:element name="ORDER_TYPE" default="Z001">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce801896811dcc66100c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

Order type

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="1" />

<xsd:maxLength value="4" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

<xsd:element name="ORDER_NAME">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce802896811dcbb3900c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

Order short text

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="0" />

<xsd:maxLength value="40" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

<xsd:element name="CO_AREA">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce803896811dcae0e00c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

Control area

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="1" />

<xsd:maxLength value="4" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

<xsd:element name="CCTR_POSTED">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce804896811dcb50900c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

CC true post

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="1" />

<xsd:maxLength value="10" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

<xsd:element name="CURRENCY">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce805896811dca87500c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

Currency

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="0" />

<xsd:maxLength value="5" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

<xsd:element name="PERSON_RESP">

<xsd:annotation>

<xsd:appinfo source="http://sap.com/xi/TextID">

577ce806896811dcaef000c045000001

</xsd:appinfo>

<xsd:documentation xml:lang="EN">

Person Rsep

</xsd:documentation>

</xsd:annotation>

<xsd:simpleType>

<xsd:restriction base="xsd:string">

<xsd:minLength value="0" />

<xsd:maxLength value="20" />

</xsd:restriction>

</xsd:simpleType>

</xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:schema>

This java code works fine as a standalone code in my machine. I am using JDK1.4.2_13. I gave the input xml file same as that I got from message mapping under SRC tab.

But when I use the same java program in my XI interface mapping I am getting the error:

Fatal Error: com.sap.engine.lib.xml.parser.ParserException: </ expected(:main:, row:1, col:101)(:main:, row=1, col=101) -> com.sap.engine.lib.xml.parser.ParserException: </ expected(:main:, row:1, col:101) at com.sap.engine.lib.xml.parser.XMLParser.scanEndTag(XMLParser.java:1872) at com.sap.engine.lib.xml.parser.XMLParser.scanElement(XMLParser.java:1846) at com.sap.engine.lib.xml.parser.XMLParser.scanDocument(XMLParser.java:2845) at com.sap.engine.lib.xml.parser.XMLParser.parse0(XMLParser.java:231) at com.sap.engine.lib.xml.parser.AbstractXMLParser.parseAndCatchException(AbstractXMLParser.java:145) at com.sap.engine.lib.xml.parser.AbstractXMLParser.parse(AbstractXMLParser.java:160) at com.sap.engine.lib.xml.parser.AbstractXMLParser.parse(AbstractXMLParser.java:261) at com.sap.engine.lib.xml.parser.Parser.parseWithoutSchemaValidationProcessing(Parser.java:280) at com.sap.engine.lib.xml.parser.Parser.parse(Parser.java:342) at com.sap.engine.lib.xml.parser.SAXParser.parse(SAXParser.java:125) at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)

Basically what I am doing in interface mapping is that I am first validating the input XI message using the schema. If the validation fails then throwing an exception, Else outputting the output xml in the output stream. The output is then mapped to target message using the graphical message mapping. The target message refers to the BAPI's output interface.

So what I doing wrong ? Why is the same java mapping code not working in XI? Is there some unicode problem in XI?

Any parser problem? My XI server is also using JDK1.4.2_13

One thing I have observed is that the code works in XI if I comment the following code lines

factory.setNamespaceAware(true);

factory.setValidating(true);

saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

saxParser.setProperty(JAXP_SCHEMA_SOURCE, new File("IOReqMsgSchema.xsd"));

Please help me! I have been struggling with this since 3 weeks now.

Thanks

Gopal

Accepted Solutions (0)

Answers (2)

Answers (2)

ranjit_deshmukh
Active Participant
0 Kudos

Hi,

is your problem solved?

if so please close the thread.

Ranjit

ranjit_deshmukh
Active Participant
0 Kudos

Hi,

just comment

factory.setNamespaceAware(true);

and then try.

I am using the DOM parser

please refer:

/people/ranjit.deshmukh/blog/2008/01/14/validations-using-java-for-those-not-having-pi71

Ranjit