Page 1 of 1

XML Validation

Posted: Sat May 11, 2019 12:21 pm
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

Re: XML Validation

Posted: Sat May 11, 2019 12:37 pm
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"

Re: XML Validation

Posted: Sat May 11, 2019 1:07 pm
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.

Re: XML Validation

Posted: Sat May 11, 2019 1:16 pm
by jan_suhr
Ok, if you run some XSLT on it in Saxon you would get the errors triggered.

Re: XML Validation

Posted: Sat May 11, 2019 1:57 pm
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!

Re: XML Validation

Posted: Fri May 31, 2019 1:13 pm
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

Re: XML Validation

Posted: Fri May 31, 2019 2:01 pm
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.

Re: XML Validation

Posted: Fri Jul 12, 2019 10:33 am
by tanhuqnh
What is the best way to validate addresses in Switch?. Is there an App?