Announcement Announcement Module
Collapse
No announcement yet.
dynamic schema location for xml validating-filter component Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • dynamic schema location for xml validating-filter component

    Hi Guys,

    i was able successfully configured a validating-filter component with hard coded schema location as follows.


    <int-xml:validating-filter discard-channel="errorChannel"
    id="bstXMLValidatingFilter"
    input-channel="bstXMLValidatorInChannel"
    output-channel="bstXMLValidatorOutChannel"
    schema-location="D:/files/xsd/Common.xsd"
    schema-type="xml-schema"
    />

    Then another requirement came, such that we need to validate different type of xml files using different xsd files and xsd file location will be defined in incoming xml as a tag. So that means incoming xml will contain their relevant xsd file name as a tag. Is there a way that we can define this schema location as xpath expression or groovy expression, so we can refer xsd dynamically?

    appreciate your help

    thanks,
    kelumt

  • #2
    There's no direct support for dynamic schemas, but you can provide a custom XmlValidator using the xml-validator attribute (mutually exclusive with schema location),

    The filter simply calls
    Code:
    validate(Source source)
    which returns an array of SAXParseException.

    Your custom validator could look at the Source and delegate to a different validator based on the input data.

    Comment


    • #3
      Hi Garry,

      Many thanks for your help. the whole day i was looking how to implement validate(Source source) , but couldn't find a solution. can you please explain the simple approach how we can tackle this approach. Here i want to know how we can validate the schema inside that method and how we inform the parent component whether the validation is success or not

      thanks,
      Kelumt

      Comment


      • #4
        Depends on your payload; if it's a String, the validator will pass in a StringSource (you can use source.toString()) to get at the String. If it's a Document, you'll get a DOMSource.

        Once you've introspected your document to find the schema you wish to validate against, simply delegate to a validator that has been configured to validate against that schema.

        You can use a XmlValidatorFactory to create each validator; see the XmlValidatingMessageSelector for how to create a validator, once you know the schema location.

        Comment

        Working...
        X