XML Validation

Post Reply
alpha4
Newbie
Posts: 4
Joined: Sat May 11, 2019 12:17 pm

XML Validation

Post by alpha4 »

Hi,

Is it possible to check an XML file before trying to process it to ensure it is a valid XML file? We've had some problems with XML files containing order information recently where the XML has cutoff half way through the file causing the file to drop out (probably because we've downloaded it from an FTP site wilst it's being uploaded), I'd like to be able to gracefully handle this and immediately alert that the problem is invalid XML (for example missing closing tags etc.)

Thanks
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: XML Validation

Post by jan_suhr »

If you run it through the "XML Pickup" element you should get the error if it is not valid. Note that the Pickup mode setting should be "Metadata is asset"
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
alpha4
Newbie
Posts: 4
Joined: Sat May 11, 2019 12:17 pm

Re: XML Validation

Post by alpha4 »

Thanks for the reply, we don't get the error at the XML Pickup unfortunately as the XML does contain some valid orders. I am hoping for a way to reject everything in the file so we have a point of truth if the file is invalid:

Usually the XML would look like this (all valid):
<?xml version="1.0"?>
<Orders_Root>
<Orders_IPN>
<Order>
<OrderLineItems>
<OrderLineItem>
<Products>
//Some Products
</Products>
</OrderLineItem>
</OrderLineItems>
</Order>
<Order>
<OrderLineItems>
<OrderLineItem>
<Products>
//Some Products
</Products>
</OrderLineItem>
</OrderLineItems>
</Order>
<Order>
<OrderLineItems>
<OrderLineItem>
<Products>
//Some Products
</Products>
</OrderLineItem>
</OrderLineItems>
</Order>
</Orders_IPN>
</Orders_Root>

The errored XML look more like this:
<?xml version="1.0"?>
<Orders_Root>
<Orders_IPN>
<Order>
<OrderLineItems>
<OrderLineItem>
<Products>
//Some Products
</Products>
</OrderLineItem>
</OrderLineItems>
</Order>
<Order>
<OrderLineItems>
<OrderLineItem>
<Products>
//Some Products
</Products>
</OrderLineItem>
</OrderLineItems>
</Order>
<Order>
<OrderLineItems>
<OrderLin

Hopefully this example helps explain my problem better.
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: XML Validation

Post by jan_suhr »

Ok, if you run some XSLT on it in Saxon you would get the errors triggered.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
alpha4
Newbie
Posts: 4
Joined: Sat May 11, 2019 12:17 pm

Re: XML Validation

Post by alpha4 »

Yeah that is where we see the failure at the minute, I was hoping there might be a success/fail path selection at this point but it doesn't seem like there is. Dropping into the problem folder is ok but I was hoping for something a little more pointed to exactly what the problem is, for example a simple email to our helpdesk or possibly the customer stating "Invalid XML, please check and resubmit" instead of the catch all problems folder.

I really appreciate your time, I'm a bit of a novice with Switch, thankyou!
borisCM
Member
Posts: 37
Joined: Mon May 06, 2019 12:23 pm
Location: Netherlands

Re: XML Validation

Post by borisCM »

first use the xml pickup
afterwards

[Metadata.Text:Path="/Orders_Root",Dataset="Xml",Model="XML"]

if this matches .+ your xml is ok
if it doesn't match .+ then your xml is corrupt
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: XML Validation

Post by jan_suhr »

alpha4 wrote: Sat May 11, 2019 1:57 pm Yeah that is where we see the failure at the minute, I was hoping there might be a success/fail path selection at this point but it doesn't seem like there is. Dropping into the problem folder is ok but I was hoping for something a little more pointed to exactly what the problem is, for example a simple email to our helpdesk or possibly the customer stating "Invalid XML, please check and resubmit" instead of the catch all problems folder.

I really appreciate your time, I'm a bit of a novice with Switch, thankyou!
The Saxon configurator has an error connection, when files end up there you can mail an message to alert.

When using the Debug option in Messages you will get a good Error log from Saxon pointing out with line in the XSLT that has the problem, this will give you a hint on what's wrong.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
tanhuqnh
Newbie
Posts: 1
Joined: Fri Jul 12, 2019 10:30 am

Re: XML Validation

Post by tanhuqnh »

What is the best way to validate addresses in Switch?. Is there an App?
Love Computer So Much !
Tùng Phát Computer
Post Reply