I was provided an XML schema that (I think) I should be able to utilize to build out the XML string that I need to send to a web service.

The two documented items in the Apex Developer Guide talk about using the DOM to generate XML and using a WSDL to generate XML which neither is applicable to the schema file.

I am not entirely sure where to start and was hoping for someone to provide some resources or insight on using a schema to build out the xml. Is this even the purpose/ possible with the schema file? I imagine the process is something like a reader or parser goes through the schema file and pulls out the tags and then I would += these tags with the appropriate data to a new XML string.

Some resources I am ready through are: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_schema.htm https://www.webucator.com/tutorial/learn-xml-schema/xml-schema-basics.cfm https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_dom.htm https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_gen_code.htm

Thank you in advance!

Update: It looks like I can use a tool like: http://xsd2xml.com/ and it will create the XML template out of the schema. From here I would parse through the XML and update the values unless there is a better way.

  • The idea might work if it's a very simple document with no optional elements and no repetition. Tools that generate XML instances from XSD aren't generally going to give you control over how many occurences of repeated or optional elements there will be. Jun 7, 2019 at 23:18
  • @MichaelKay do you have any suggestions then on how to go about using a fairly large schema to build out xml?
    – Olivia
    Jun 13, 2019 at 19:35
  • 1
    I wouldn't use the schema, except to validate that the XML you're generating is valid. I would typically write a schema-aware XSLT 2.0 stylesheet that validates the result document as it writes it. Jun 13, 2019 at 22:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy