This ensures that the book type will be interpreted correctly by the schema when the XML document is validated. Note that it is important to set the xsi:type attribute of the newly created book. Values of attributes and elements can be accessed using the Value property of the generated member element or attribute class, for example:ĭictionary. Reading and writing elements and attributes
XMLSPY HANDBOOK CODE
If the code was executed successfully, Library.xml will be read by the program code, and its contents displayed as console output. Throw new Exception ( "Unexpected book type" ) Ĥ.Press F5 to start debugging. WriteLine ( "Language to: " + dictionary. WriteLine ( "Language from: " + dictionary. Equals ( prefix + ":DictionaryType" ))ĭictionaryType dictionary = new DictionaryType ( book. Get the namespace URI and the lookup prefix of this namespace Find the value of the xsi:type attribute Determine if this book is of derived type WriteLine ( "This is a paperback book." ) įoreach ( xs. Output values of ID attribute and (first and only) title elementĬonsole. WriteLine ( "The library generation date is: " + dt_as_string )
![xmlspy handbook xmlspy handbook](http://www.bioline.org.br/showimage?st/photo/st05018f13.jpg)
This is the file that will be read by the program code.ĭoc2 doc = Doc2. Open the LibraryTest.sln solution in Visual Studio.Ģ.Save the code below as Library.xml to the output directory of the project (by default, bin/Debug). If the code was executed successfully, a GeneratedLibrary.xml file is created in the solution output directory (typically, bin/Debug).ġ. SaveToFile ( "GeneratedLibrary.xml", true ) ģ.Press F5 to start debugging. Save the XML document with the "pretty print" option enabledĭoc. your schema is not in the same folder as the generated instance file)ĭoc. Optionally, set the schema location (adjust the path if Since it's a derived type, make sure to set the xsi:type attribute of the book element Value = "English-German Dictionary" ĭictionary. Append a dictionary (book of derived type) and populate its attributes and elementsĭictionaryType dictionary = new DictionaryType ( root.
![xmlspy handbook xmlspy handbook](https://flylib.com/books/1/487/1/html/2/images/0228.jpg)
Set the format of the book (enumeration)īook. Create the generation date using Altova DateTime classĪltova. As illustrated in the diagram below, the class DictionaryType inherits the BookType class. Since the DictionaryType is a complex type derived from BookType in the schema, this relationship is also reflected in the generated classes. Such classes enable you to manipulate programmatically the corresponding elements and attributes in the instance XML document (for example, append, remove, set value, etc).
![xmlspy handbook xmlspy handbook](https://flylib.com/books/1/487/1/html/2/images/0801.jpg)
Examples of such classes are MemberAttribute_ID and MemberElement_Author, generated from the Author element and ID attribute of a book, respectively (in the diagram below, they are classes nested under BookType). In the generated code, the name of such member classes is prefixed with MemberAttribute_ and MemberElement_, respectively. The Library member of the Doc2 class represents the actual root of the document.Īccording to the code generation rules mentioned in About Schema Wrapper Libraries (C#), member classes are generated for each attribute and for each element of a type.