BPEL how to remove invalid (over schema validation) nodes from XML — oracle-tech

    Forum Stats

  • 3,702,035 Users
  • 2,239,551 Discussions
  • 7,835,727 Comments

Discussions

BPEL how to remove invalid (over schema validation) nodes from XML

Damir DevDamir Dev Posts: 43
edited July 2019 in SOA Suite Discusssions

Hello!

I want to find invalid nodes in XML over schema validation and remove it from XML.

I have

1. XSD

...

<xs:element name="Client" type="tns:ClientType" maxOccurs="unbounded"/>

<xs:complexType name="tns:ClientType">

<xs:sequence>

<xs:element name="ClientId" type="xs:int" minOccurs="1">

<xs:element name="MiddleName" type="xs:string" minOccurs="0"/>

<xs:element name="Birthday" type="xs:date" minOccurs="1">

<xs:element name="Comment" minOccurs="1">

  <xs:simpleType>

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

      <xs:maxLength value="5"/>

    </xs:restriction>

  </xs:simpleType>

</xs:element>

...

</xs:sequence>

</xs:complexType>

...

2. XML

    <Client>

      <ClientId>1</ClientId>

      <MiddleName>MiddleName1</MiddleName>

      <Birthday>1988-09-29</Birthday>

      <Comment>Com1</Comment>

      ...

    </Client>

    <Client>

      <ClientId>2</ClientId>

      <MiddleName>MiddleName2</MiddleName>

      <Birthday>not found</Birthday>

      <Comment>Com2</Comment>

      ...

    </Client>

    <Client>

      <MiddleName>MiddleName</MiddleName>

      <Birthday>1988-03-03</Birthday>

      <Comment>Com</Comment>

      ...

    </Client>

    <Client>

      <ClientId>3</ClientId>

      <MiddleName>MiddleName3</MiddleName>

      <Birthday>1986-06-09</Birthday>

      <Comment>Comment3</Comment>

      ...

    </Client>

Expected result

    <Client>

      <ClientId>1</ClientId>

      <MiddleName>MiddleName1</MiddleName>

      <Birthday>1988-09-29</Birthday>

      <Comment>Com1</Comment>

      ...

    </Client>

A Validate Activity fault does not provide information which one from "Client" nodes is not valid. A Schematron it is not XSD validation.

Could you tell me please how to remove invalid "Client" nodes from XML?

Tagged:

Best Answer

  • Martien van den AkkerMartien van den Akker Posts: 2,756 Bronze Crown
    edited June 2019 Accepted Answer

    Yes that could work, looping over the node and check them one by one. But indeed, with large payloads, many occurrences it would be performance expensive.

    But if you can define a proper set of possible faults, you can do the xslt first, and if that still results in an invalid xml, do a one by one validation of the elements? Then you have at least filtered the most common ones, and only do a throrough check if that fails to result in a valid xml.

    However, if you would need to register which elements are ignored because of invalidity, you should perform the looped-one-by-one validation.


    Regards,
    Martien

Answers

  • Martien van den AkkerMartien van den Akker Posts: 2,756 Bronze Crown
    edited June 2019

    Hi,


    There's no activity that can do that. What you should do is create a transformation that only copies a client element if it applies to a set of conditions that you  define in the if/choose-when tests.

    This is also the way to have a semantic validation of an xml.

    Regards,
    Martien

  • Damir DevDamir Dev Posts: 43
    edited June 2019

    Thank you, Martien.

    Yes, its no bad idea, if does not change xsd often. So I try find a more universal idea. For example, in cycle split xml for few saparate xml's with one "Client" node only and then make xsd validation, create new common xml:

    1) if will  be validation success, then add current Client node to xml

    2) if will  be validation fault, then catch it and ignore it

    It is need in more spending time for process when a lot nodes, so it is not a best design.

  • Martien van den AkkerMartien van den Akker Posts: 2,756 Bronze Crown
    edited June 2019 Accepted Answer

    Yes that could work, looping over the node and check them one by one. But indeed, with large payloads, many occurrences it would be performance expensive.

    But if you can define a proper set of possible faults, you can do the xslt first, and if that still results in an invalid xml, do a one by one validation of the elements? Then you have at least filtered the most common ones, and only do a throrough check if that fails to result in a valid xml.

    However, if you would need to register which elements are ignored because of invalidity, you should perform the looped-one-by-one validation.


    Regards,
    Martien

Sign In or Register to comment.