0

Dear fellow exchangers,

For a project I'm expected to generate a xml file of previously defined format, which includes a inline schema. This xml is then communicated with other software running on another computer.

The script is running on a siemens runtime HMI, which seems to sometimes influence the exact capabilities.

I am not looking to validate the xml, I just wish to include (preferably from .xsd file) an inline schema.

I've been trying to find a decent way but have not stumbled upon any methods that should be used for doing so. I've been successful in putting out the xml data, but not with the schema inline.

I've tried mostly to find a suitable method, which lead to trying to using 'textattribute'. Reading the .xsd file with 'opentextfile', converting the content to string and then using that string to add as textattribute.

As I do believe this might be viable, I also ran into the issue that <,> is converted to < , > I have not yet found a solution for this, and I would like to avoid having to try and script the building of the complete schema...As it has already been build completely.

I apologise as for any vagueness, please do comment how to form my question more clearly if necessary.

Greetings

1 Answers1

0

As your problem concerns XML, "textattribute", "opentextfile", and "to string" are obviously bad concepts/ideas.

Let oXml1 be your data Msxml2.DOMDocument (just created/loaded) and oXsd1 your loaded schema. Then

  Dim r : Set r = oXml1.documentElement
  r.insertBefore oXml1.createComment("END OF SCHEMA"), r.firstChild
  r.insertBefore oXsd1.documentElement, r.firstChild
  r.insertBefore oXml1.createComment("START OF SCHEMA"), r.firstChild

will give you something like

<?xml version="1.0"?>
<catalog xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:x="urn:book">
        <!-- START OF SCHEMA -->
        <xsd:schema targetNamespace="urn:book">
                <xsd:element name="book">
                        <xsd:complexType>
                                <xsd:sequence>
                                        <xsd:element name="author" type="xsd:string"/>
                                        <xsd:element name="title" type="xsd:string"/>
                                </xsd:sequence>
                                <xsd:attribute name="id" type="xsd:string"/>
                        </xsd:complexType>
                </xsd:element>
        </xsd:schema>
        <!-- END OF SCHEMA -->
        <x:book id="bk101">
                <author>Gambardella, Matthew</author>
                <title>XML Developer's Guide</title>
        </x:book>
</catalog>
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Dear Ekkehard Horner, I've been busy trying to get this to work but seem to fail at loading the schema. Should it also be loaded as a domdocument? or as XMLSchemaCache? When I create another domdocument, and use this, I get no error but the file doesn't change...And for XMLSchemaCache I get an error, documentElement method not allowed. – user3603231 May 06 '14 at 07:11
  • @user3603231 the .xsd shoulkd be loaded as/in a domdocument (we need its documentElement after all); the .xml *file* won't be changed unless you .Save it. – Ekkehard.Horner May 06 '14 at 07:47
  • Yes, I wanted to update my comment but this is not allowed after 5 mins. Although also not allowed, thank you for your help (I can't vote on your answer). The file was being saved to a network location, and was not updated! It is working fine now so it appears to be a matter of access permissions, thank you once more. – user3603231 May 06 '14 at 08:02