API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  api connect map policy error policy=map : Output output: Invalid XML schema encountered

    Posted Thu September 19, 2024 01:39 PM

    I am trying to test jsontoxmlpolicy below are the steps I configured .I just want to parse the inout and save it to an variable. Use that variable in jsontoxml policy save output in a variable.how can I achieve this?

    1)parse policy with Message for resulting parsed data mapped to element responseMessage.

    2)json-to-xml policy with input configured to  responseMessage output is given empty .

    3)map policy to map input responseMessage.body to message.body as output.

    I am receiving the  below error.

     "moreInformation": "Map: API=testjsontosoapconversion, policy=map : Output output: Invalid XML schema encountered, multiple elements or no elements: ; cannot be specified at the root document level."
    }



    ------------------------------
    vk k
    ------------------------------


  • 2.  RE: api connect map policy error policy=map : Output output: Invalid XML schema encountered

    Posted Fri September 20, 2024 09:06 AM

    Hi VK,
    In my simple test, the json-to-xml policy took input message responseMessage and converted the JSON to XML, writing the XML to the context message responseMessage in place.  That should be what you're seeing since you're expecting the map input to be getting XML input from responseMessage.body.  The map policy is schema driven for both the inputs and outputs, and when you specify that an input or output is application/xml, the schema will be examined to ensure you have one and only one root element in the schema.  The error message is indicating that your schema for the output named output is invalid.  What does the map policy and its output schema look like?

    Best Regards,
    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 3.  RE: api connect map policy error policy=map : Output output: Invalid XML schema encountered

    Posted Sat September 28, 2024 09:20 PM

    Sorry for the delayed message Steve Linn,below is the code I am using

    - operations:
                    - verb: post
                      path: /testjsontoxml
                  execute:
                    - parse:
                        version: 2.2.0
                        title: parse
                        parse-settings-reference:
                          parse-settings:
                            document_type: json
                            max_doc_size: 900
                            max_width: 440
                            max_nesting_depth: 300
                            max_name_length: 50
                            max_value_length: 70
                        input: ''
                        output: responsemessage
                    - json-to-xml:
                        version: 2.0.0
                        title: json-to-xml
                        root-element-name: json
                        always-output-root-element: false
                        unnamed-element-name: response
                        input: responsemessage
                        output: responsemessage

                        conversionType: relaxed-badgerfish
                    - map:
                        version: 2.1.0
                        title: map
                        inputs:
                          input:
                            schema:
                              type: object
                            variable: responsemessage
                            content: application/xml
                        outputs:
                          output:
                            schema:
                              type: object
                            variable: message.body
                            content: application/xml
                        actions:
                          - set: output
                            from: input



    ------------------------------
    v k
    ------------------------------



  • 4.  RE: api connect map policy error policy=map : Output output: Invalid XML schema encountered

    Posted Sat September 28, 2024 09:20 PM

    Sorry for the delayed message Steve Linn,below is the code I am using

    - operations:
                    - verb: post
                      path: /testjsontoxml
                  execute:
                    - parse:
                        version: 2.2.0
                        title: parse
                        parse-settings-reference:
                          parse-settings:
                            document_type: json
                            max_doc_size: 900
                            max_width: 440
                            max_nesting_depth: 300
                            max_name_length: 50
                            max_value_length: 70
                        input: ''
                        output: responsemessage
                    - json-to-xml:
                        version: 2.0.0
                        title: json-to-xml
                        root-element-name: json
                        always-output-root-element: false
                        unnamed-element-name: response
                        input: responsemessage
                        output: responsemessage

                        conversionType: relaxed-badgerfish
                    - map:
                        version: 2.1.0
                        title: map
                        inputs:
                          input:
                            schema:
                              type: object
                            variable: responsemessage
                            content: application/xml
                        outputs:
                          output:
                            schema:
                              type: object
                            variable: message.body
                            content: application/xml
                        actions:
                          - set: output
                            from: input



    ------------------------------
    v k
    ------------------------------



    ------------------------------
    v k
    ------------------------------



  • 5.  RE: api connect map policy error policy=map : Output output: Invalid XML schema encountered

    Posted Tue October 01, 2024 12:20 PM
    tetetsts





  • 6.  RE: api connect map policy error policy=map : Output output: Invalid XML schema encountered

    Posted Tue October 01, 2024 01:21 PM

    Hi VK,
    In your map input configuration, your variable should be variable: responsemessage.body

    As for your schemas, the error you are seeing is from your output schema:

                        outputs:
                          output:
                            schema:
                              type: object
                            variable: message.body
                            content: application/xml

    The map policy actually does all of its mapping using JSON objects.  For XML output, it then uses the output schema and the JSON output object to create the XML structure that is desired.  A schema of simply "type: object" is insufficient.  It must be a schema that totally describes the XML output structure.  I would suggest taking an example XML output and instead of an output type of object, choose inline schema.  That will allow you to create an XML schema using your example XML.  Then the map policy will have the schema it needs to produce the desired XML output.

    Best Regards,
    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------