cancel
Showing results for 
Search instead for 
Did you mean: 

XML Validation: ignore non-XML-Header in XML-file(payload): any solutions?

Former Member
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

udo_martens
Active Contributor
0 Kudos

Hi Armin,

any characters before the prolog will lead to "not wellformed" xml

You can delete such a header during runtime with a non-parsing mapping (ABAP or Java, not xsl or MM). But the validation will take place before.

What you could do (very complex...): You map the message in a first step and delete the header (or put it inside the message if you need it). As mentioned only with non-parsing ABAP or Java. This message is gonna be routed to a virtual http server, in the receiver adapter you put just the address of the PI server. That means the message will go PI a second time, where you can validate the message (in addition you would be able to use a Message Mapping). Disadvantage would be to have always to PI messages and a very complex design.

Regards,

Udo

Former Member
0 Kudos

Thank you for your answer, Udo.

The Header already is in the payload/message (or what message do you mean?). I hope I used the term "header" correctly in this context, as it is just 2 lines in the payload.

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?

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..

udo_martens
Active Contributor
0 Kudos

Hi Armin,

> 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)

> 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

Former Member
0 Kudos

Thanks again, Udo.

Sounds interesting, but as a beginner this task is out of my range. Maybe I'm able to realise it in 2 or 3 years

Anyway, in your first solution, withou validation: why should the header still be removed? If it's just mapping, couldn't we just adopt the header in the new message?

However, as we don't use any mappings so far and only work with Adapter Engine (and not Integration Server) that's a bit out of my league

udo_martens
Active Contributor
0 Kudos

Hi Armin,

you need to remove the "header" for any validation or mapping.

You should look forward to an interesting task*. For any detail questions you have the SDN.

Regards,

Udo

*Durch Aufgeben ist noch keine Partie gewonnen worden (Tartakower)

Former Member
0 Kudos

Which version of PI are you using?

If it is PI 7.1 or below, you will have your xsds stored in a app server file location. If this is the case, the simplest way to achieve your goal is write a simple java mapping that will take 1 parameter (XSD file location) and do the validation in Java.

XSD validation in Java is very straight forward just google for it.

We used this approach to achieve XSD validation + header/trailer validation as a single step.

Jai

Former Member
0 Kudos

We're using SAP PI 7.11 SPS8, the XSD file is in the file system

(...)/j2ee/cluster/server0/validation/schema/(...)

Do you think your solution works with 7.11?

I never mapped anything before (I'm a student, all new to this topic) and my java knowledge is small, but I'll try to google around a bit.

Former Member
0 Kudos

We're using SAP PI 7.11 SPS8, the XSD file is in the file system

(...)/j2ee/cluster/server0/validation/schema/(...)

Do you think your solution works with 7.11?

It will. 100%

I never mapped anything before (I'm a student, all new to this topic) and my java knowledge is small, but I'll try to google around a bit.

Java mapping in PI is quite simple. There are many blogs in SDN on Java mapping. The logic would be to remove the header from the xml before calling the validator and then add it again after validation.

Jai

Answers (1)

Answers (1)

Former Member
0 Kudos

Error -- you must post a comment or follow-up.

..here we go.