In XML Schema the attribute "default" for the element doesn't create element when it's absent but only supplies value when it's empty. I need elements that do not exist in XML to be created by schema. I have XML file:
I want result to be <myelement1>1</myelement1> <myelement2>2</myelement2> <myelement3>3</myelement3>
Thank you, Vladas
P.S. I am not sure if schema will do that for me. As I found out XML schemas and XSL Transformations are somewhat limited and sometimes you have to code some transformation i.e. with Java. I hope this not the case
Joined: Jan 23, 2002
Validating an XML document against a schema shouldn't modify the document in any way. The default attribute being present in a schema is a note to the programmer that the application processing instances of that schema will interpret a missing value as the given default value. If you want to replace such missing values/elements, I'm afraid you'll have to do it yourself (using XSLT or Java's DOM API, for example).
I heard that XSLT 2.0 works with types and schemas. Maybe I can use XSLT to "create" missing elements. I have configuration file which may have or not have some values. If it does not have required element entry it should create one based on default value. I am using XSD to specify ALL the elements. Can I walk XML and XSD with XSLT and create resulting XML based not on what entries are in config XML but rather on which entries are described in XSD? I.e. template match by type.
Another idea is to parse not XML but XSD itself.. I do hesitate to put configuration entries as attributes and not as elements because in my opinion it will make larger XSD and will reduce configuration file template readability.
Joined: Dec 02, 2003
I dont have much experience with XML yet but as I understand:
I make all configuration file as single element and all it's parameters as attributes. In this case missing attributes can be created using "default". But attributes can be only simpleType and hmm each configuration entry is:
Name, Type, Short Description, Long Description, Validation rules...