This document discusses XML and the Document Object Model (DOM). It introduces XML documents and namespaces. It describes how the DOM represents an XML document as a tree structure with parent and child nodes. It provides code examples for reading an XML file using an XmlReader, and manipulating an XML document's DOM tree by building a copy of the tree as TreeNodes in a TreeView control.
Web Developement Workshop (Oct 2009) SlidesManish Sinha
This document provides an overview of web development technologies including HTML, CSS, PHP, MySQL, and forms. It includes brief introductions and code snippets for each topic. Key points covered are basic HTML tags and structure, CSS styling, SQL commands for managing a MySQL database, PHP syntax and functions, and using forms to pass data between pages. Contact information is also provided for three web developers.
This document provides an overview of Spec#, a programming language extension developed by Microsoft Research that allows developers to add formal specifications and contracts to .NET programs. Some key points:
- Spec# adds preconditions, postconditions, and object invariants that define contracts between method implementations and callers. These specifications can be checked to find errors.
- It supports Visual Studio and emits checks to downstream tools like Boogie to perform formal verification of Spec# programs.
- Spec# aims to eliminate null reference errors by distinguishing non-null (!) and possibly null (?) reference types and enforcing these properties.
- Examples are provided showing how method specifications, modifiers, and object invariants are defined in Spec#
R package development, create package documentation isabella golliniDataFest Tbilisi
This document provides an overview of creating package documentation using roxygen2 and R markdown. It discusses writing function documentation with roxygen2 comments, previewing documentation locally, and creating package documentation like vignettes using R markdown. The document demonstrates the documentation workflow and encourages documenting other objects like data and classes. It also introduces creating package websites using pkgdown to showcase the package documentation.
This document describes a Java implementation of sentence boundary detection. It uses regular expressions to find candidate sentence boundaries, then applies additional rules to validate whether the candidate is a true boundary or not, such as checking if the last word is an abbreviation. It returns true if at least one valid sentence boundary is found in the given text.
The document contains questions asking to write HTML code for various tags and controls like lists, tables, images, links etc. It also contains questions asking to write programs to calculate factorial, GCD, add numbers etc using JavaScript, VBScript with HTML code. The questions cover basic to intermediate level HTML and scripting concepts.
The document provides an introduction to XML including:
- XML is an extensible markup language used to store and transport data, often over the Internet.
- XML documents form a tree structure with elements forming parent-child relationships.
- The XML DOM defines a standard way to access and manipulate XML documents and presents them as a tree structure.
- XPath uses path-like syntax to navigate XML documents and select nodes.
- XSLT is used to transform XML documents into other formats like HTML.
- DTDs and XML Schemas define the structure and elements of XML documents and are used to validate their structure.
1. The document discusses JavaScript objects and their properties and methods. It covers the Math, String, Date, Boolean and Number objects.
2. Various string methods are described, including searching/splitting strings, character processing, and HTML markup methods.
3. The document provides examples of using string methods like charAt(), indexOf(), split(), and substring() to manipulate and process strings.
Web Developement Workshop (Oct 2009) SlidesManish Sinha
This document provides an overview of web development technologies including HTML, CSS, PHP, MySQL, and forms. It includes brief introductions and code snippets for each topic. Key points covered are basic HTML tags and structure, CSS styling, SQL commands for managing a MySQL database, PHP syntax and functions, and using forms to pass data between pages. Contact information is also provided for three web developers.
This document provides an overview of Spec#, a programming language extension developed by Microsoft Research that allows developers to add formal specifications and contracts to .NET programs. Some key points:
- Spec# adds preconditions, postconditions, and object invariants that define contracts between method implementations and callers. These specifications can be checked to find errors.
- It supports Visual Studio and emits checks to downstream tools like Boogie to perform formal verification of Spec# programs.
- Spec# aims to eliminate null reference errors by distinguishing non-null (!) and possibly null (?) reference types and enforcing these properties.
- Examples are provided showing how method specifications, modifiers, and object invariants are defined in Spec#
R package development, create package documentation isabella golliniDataFest Tbilisi
This document provides an overview of creating package documentation using roxygen2 and R markdown. It discusses writing function documentation with roxygen2 comments, previewing documentation locally, and creating package documentation like vignettes using R markdown. The document demonstrates the documentation workflow and encourages documenting other objects like data and classes. It also introduces creating package websites using pkgdown to showcase the package documentation.
This document describes a Java implementation of sentence boundary detection. It uses regular expressions to find candidate sentence boundaries, then applies additional rules to validate whether the candidate is a true boundary or not, such as checking if the last word is an abbreviation. It returns true if at least one valid sentence boundary is found in the given text.
The document contains questions asking to write HTML code for various tags and controls like lists, tables, images, links etc. It also contains questions asking to write programs to calculate factorial, GCD, add numbers etc using JavaScript, VBScript with HTML code. The questions cover basic to intermediate level HTML and scripting concepts.
The document provides an introduction to XML including:
- XML is an extensible markup language used to store and transport data, often over the Internet.
- XML documents form a tree structure with elements forming parent-child relationships.
- The XML DOM defines a standard way to access and manipulate XML documents and presents them as a tree structure.
- XPath uses path-like syntax to navigate XML documents and select nodes.
- XSLT is used to transform XML documents into other formats like HTML.
- DTDs and XML Schemas define the structure and elements of XML documents and are used to validate their structure.
1. The document discusses JavaScript objects and their properties and methods. It covers the Math, String, Date, Boolean and Number objects.
2. Various string methods are described, including searching/splitting strings, character processing, and HTML markup methods.
3. The document provides examples of using string methods like charAt(), indexOf(), split(), and substring() to manipulate and process strings.
This document appears to be a student project submission for a post graduate diploma in information technology. It contains two questions and answers involving C programming. Question 1 involves accepting integer values from the user, sorting an array in ascending order, calculating the sum of odd values and number of even values. Question 2 involves reading from a file passed as a command line argument, displaying each word on a new line, counting vowels, occurrences of "the", and copying the file contents to a new file. The code provided implements the specified tasks for each question.
The document discusses Document Type Definitions (DTDs) and XML Schema, which are used to define the structure and validate XML documents. It provides information on DTD elements like declarations, internal and external DTDs. It also covers XML Schema topics such as data types, elements, attributes, namespaces and advantages over DTDs like richer data types and extensibility.
Introduction to web programming with JavaScriptT11 Sessions
This document provides an overview of web programming with JavaScript. It discusses topics like:
- HTML and CSS which are used to structure and style web pages
- How browsers interpret HTML, CSS, and JavaScript to display web pages
- What backend and frontend development involve
- Common JavaScript concepts like variables, operators, functions, and events
- Tools that can be used for web development like text editors, browsers, and version control software
- Resources for learning more about JavaScript and web programming
The document discusses various scenarios involving custom formatters, validators, and effects in Flex applications. It provides examples of creating a custom formatter to format strings in a specific way, a custom validator to validate passwords based on certain criteria, and discusses how custom effects could be created by extending the appropriate base classes and overriding core methods. The examples demonstrate how to extend built-in Flex classes to achieve custom formatting, validation, and effects as needed for different application requirements.
This document discusses principles for writing clean code in functions. It recommends that functions should be small, do one thing, have descriptive names, and avoid side effects. Functions with many arguments or switch statements are harder to understand. Exceptions should be used instead of return codes to indicate errors. Overall, following best practices for functions helps produce code that is easy to read and maintain.
The document provides an overview of SQL and PHP for working with databases. It discusses SQL concepts like creating and modifying tables, inserting and selecting data. It then covers connecting to databases from PHP, executing SQL queries from PHP, and processing HTML forms to insert data into databases using PHP. Key topics include SQL syntax for common operations, the basic PHP code for connecting to MySQL, running queries, and retrieving result rows, and using the $_POST array to access form data submitted to a PHP processing page.
Preon is a declarative data binding framework for Java that allows mapping data structures to binary encoded representations. It generates decoders, encoders, and documentation automatically based on annotations on the data structure classes. This avoids the need for manual parsing of bit streams and improves maintainability. Preon uses a chain of Codec objects to handle each encoding/decoding task, keeping the logic encapsulated and modular. It supports features like expressions, lazy loading, inheritance and custom CodecFactories to handle different data types. The goal is to hide the complexity of binary encoding and make working with binary data as easy as working with regular Java objects.
This deck was used to conduct a hands-on workshop at Mumbai Tech Meetup. It covers an introduction to Go, core language features, Object Oriented features of Go, Concurrency, API Servers and more.
Jquery is a JavaScript library that simplifies HTML document traversal, event handling, animating, and Ajax interactions. It is built on JavaScript and provides shortcuts and abstractions for many common tasks. Some key benefits of Jquery include providing cross-browser compatibility, an easy to use syntax, and a large number of plugins and functions to extend its capabilities.
PHP Basics provides an overview of PHP syntax and variables. It explains how to define and assign variables, use data types like strings and arrays, and perform basic operations. Key points covered include using comments, semicolons, variable naming rules, operators, and the difference between echo and print statements. Constants and predefined variables are also summarized.
This document discusses string comparison and manipulation functions in PHP. It explains how to encode, escape and decode strings for HTML, and compares different functions for comparing strings like strcmp(), strcasecmp(), similar_text() and levenshtein(). It also covers removing HTML tags with strip_tags(), adding and removing slashes with addslashes() and stripslashes(), and approximate string comparison using soundex() and metaphone().
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
The document discusses embedded domain-specific languages (DSLs) for Java and provides two case studies:
1) Building SQL queries using a typesafe DSL that avoids errors and allows type inference.
2) Modifying Java bytecode using the ASM library to define a DSL for bytecode engineering.
Perl is a very feature-rich language, which clearly cannot be discussed in full detail here. Instead, our
goals here are to (a) enable the reader to quickly become proficient at writing simple Perl programs and (b)
prepare the reader to consult full Perl books (or Perl tutorials on the Web) for further details of whatever
Perl constructs he/she needs for a particular application.
Our approach here is different from that of most Perl books, or even most Perl Web tutorials. The usual
approach is to painfully go over all details from the beginning. For example, the usual approach would be
to state all possible forms that a Perl literal can take on.
We avoid this here. Again, the aim is to enable the reader to quickly acquire a Perl foundation. He/she should
then be able to delve directly into some special topic, with little or not further learning of foundations.
This document provides an overview of JavaScript fundamentals including:
1. A brief history of JavaScript including its development by Netscape and standardization by ECMA and W3C.
2. The uses of JavaScript including creating interactive pages, generating HTML dynamically, handling events, and enhancing browser capabilities.
3. Key JavaScript language features such as its object-based nature, syntax similar to C++ and Java, and platform independence.
4. How to include scripts in HTML using <script> tags and handling browsers that don't support scripts with <noscript>.
5. Details on variables and data types, operators, control structures, arrays, and functions in JavaScript.
The document discusses various topics related to Visual Basic 6.0 including its integrated development environment, controls, statements, operators, variables, data types, and message boxes. It provides descriptions and examples of forms, controls, programming concepts, and functions in Visual Basic.
The document discusses using Ragel and Lemon to generate parsers. It provides an overview of lexical analysis and syntax analysis in parsing. Ragel is introduced as a state machine generator that can be used to implement a lexer. A Ragel example tokenizes mathematical expressions. Lemon is a parser generator that outputs code to implement a parser based on a defined grammar. A Lemon example parses mathematical expressions. Finally, the document shows how to combine a Ragel lexer and Lemon parser to build a calculator application that can evaluate expressions.
The document describes how to search directories and files using the File and Directory classes in C#. It defines a regular expression to match file extensions and stores the number of files found for each extension. The program recursively searches all subdirectories, counts the number of files for each extension, and outputs a summary of the results. It also checks for and allows deleting any backup (.bak) files found.
This document provides an introduction to basic electronics concepts including electricity, voltage, current, resistance, LEDs, Ohm's law, and capacitors. It covers the following key points in 3 sentences:
The document defines basic concepts of electricity including how electrons flow in conductors to create currents, and defines voltage and current. It explains how voltage, current, and resistance are related by Ohm's law and how to measure these quantities using a multimeter. Various circuit components such as LEDs, resistors, capacitors, and breadboards are introduced along with exercises to apply concepts of series and parallel circuits.
The document describes object-oriented programming concepts like classes, objects, encapsulation, and properties. It provides code examples of a Time class that encapsulates time data and provides methods to work with it. The Time class uses properties to safely access private member variables for hour, minute and second. Constructors are demonstrated that initialize Time objects with different parameters.
The document discusses various graphical user interface controls in C#, including menus, link labels, list boxes, combo boxes, tree views, and tab controls. It provides code examples to demonstrate how to implement menus with options to change font colors and styles, as well as link labels that link to other programs or files when clicked. Event handlers are used to handle user interactions with the controls.
This document appears to be a student project submission for a post graduate diploma in information technology. It contains two questions and answers involving C programming. Question 1 involves accepting integer values from the user, sorting an array in ascending order, calculating the sum of odd values and number of even values. Question 2 involves reading from a file passed as a command line argument, displaying each word on a new line, counting vowels, occurrences of "the", and copying the file contents to a new file. The code provided implements the specified tasks for each question.
The document discusses Document Type Definitions (DTDs) and XML Schema, which are used to define the structure and validate XML documents. It provides information on DTD elements like declarations, internal and external DTDs. It also covers XML Schema topics such as data types, elements, attributes, namespaces and advantages over DTDs like richer data types and extensibility.
Introduction to web programming with JavaScriptT11 Sessions
This document provides an overview of web programming with JavaScript. It discusses topics like:
- HTML and CSS which are used to structure and style web pages
- How browsers interpret HTML, CSS, and JavaScript to display web pages
- What backend and frontend development involve
- Common JavaScript concepts like variables, operators, functions, and events
- Tools that can be used for web development like text editors, browsers, and version control software
- Resources for learning more about JavaScript and web programming
The document discusses various scenarios involving custom formatters, validators, and effects in Flex applications. It provides examples of creating a custom formatter to format strings in a specific way, a custom validator to validate passwords based on certain criteria, and discusses how custom effects could be created by extending the appropriate base classes and overriding core methods. The examples demonstrate how to extend built-in Flex classes to achieve custom formatting, validation, and effects as needed for different application requirements.
This document discusses principles for writing clean code in functions. It recommends that functions should be small, do one thing, have descriptive names, and avoid side effects. Functions with many arguments or switch statements are harder to understand. Exceptions should be used instead of return codes to indicate errors. Overall, following best practices for functions helps produce code that is easy to read and maintain.
The document provides an overview of SQL and PHP for working with databases. It discusses SQL concepts like creating and modifying tables, inserting and selecting data. It then covers connecting to databases from PHP, executing SQL queries from PHP, and processing HTML forms to insert data into databases using PHP. Key topics include SQL syntax for common operations, the basic PHP code for connecting to MySQL, running queries, and retrieving result rows, and using the $_POST array to access form data submitted to a PHP processing page.
Preon is a declarative data binding framework for Java that allows mapping data structures to binary encoded representations. It generates decoders, encoders, and documentation automatically based on annotations on the data structure classes. This avoids the need for manual parsing of bit streams and improves maintainability. Preon uses a chain of Codec objects to handle each encoding/decoding task, keeping the logic encapsulated and modular. It supports features like expressions, lazy loading, inheritance and custom CodecFactories to handle different data types. The goal is to hide the complexity of binary encoding and make working with binary data as easy as working with regular Java objects.
This deck was used to conduct a hands-on workshop at Mumbai Tech Meetup. It covers an introduction to Go, core language features, Object Oriented features of Go, Concurrency, API Servers and more.
Jquery is a JavaScript library that simplifies HTML document traversal, event handling, animating, and Ajax interactions. It is built on JavaScript and provides shortcuts and abstractions for many common tasks. Some key benefits of Jquery include providing cross-browser compatibility, an easy to use syntax, and a large number of plugins and functions to extend its capabilities.
PHP Basics provides an overview of PHP syntax and variables. It explains how to define and assign variables, use data types like strings and arrays, and perform basic operations. Key points covered include using comments, semicolons, variable naming rules, operators, and the difference between echo and print statements. Constants and predefined variables are also summarized.
This document discusses string comparison and manipulation functions in PHP. It explains how to encode, escape and decode strings for HTML, and compares different functions for comparing strings like strcmp(), strcasecmp(), similar_text() and levenshtein(). It also covers removing HTML tags with strip_tags(), adding and removing slashes with addslashes() and stripslashes(), and approximate string comparison using soundex() and metaphone().
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
The document discusses embedded domain-specific languages (DSLs) for Java and provides two case studies:
1) Building SQL queries using a typesafe DSL that avoids errors and allows type inference.
2) Modifying Java bytecode using the ASM library to define a DSL for bytecode engineering.
Perl is a very feature-rich language, which clearly cannot be discussed in full detail here. Instead, our
goals here are to (a) enable the reader to quickly become proficient at writing simple Perl programs and (b)
prepare the reader to consult full Perl books (or Perl tutorials on the Web) for further details of whatever
Perl constructs he/she needs for a particular application.
Our approach here is different from that of most Perl books, or even most Perl Web tutorials. The usual
approach is to painfully go over all details from the beginning. For example, the usual approach would be
to state all possible forms that a Perl literal can take on.
We avoid this here. Again, the aim is to enable the reader to quickly acquire a Perl foundation. He/she should
then be able to delve directly into some special topic, with little or not further learning of foundations.
This document provides an overview of JavaScript fundamentals including:
1. A brief history of JavaScript including its development by Netscape and standardization by ECMA and W3C.
2. The uses of JavaScript including creating interactive pages, generating HTML dynamically, handling events, and enhancing browser capabilities.
3. Key JavaScript language features such as its object-based nature, syntax similar to C++ and Java, and platform independence.
4. How to include scripts in HTML using <script> tags and handling browsers that don't support scripts with <noscript>.
5. Details on variables and data types, operators, control structures, arrays, and functions in JavaScript.
The document discusses various topics related to Visual Basic 6.0 including its integrated development environment, controls, statements, operators, variables, data types, and message boxes. It provides descriptions and examples of forms, controls, programming concepts, and functions in Visual Basic.
The document discusses using Ragel and Lemon to generate parsers. It provides an overview of lexical analysis and syntax analysis in parsing. Ragel is introduced as a state machine generator that can be used to implement a lexer. A Ragel example tokenizes mathematical expressions. Lemon is a parser generator that outputs code to implement a parser based on a defined grammar. A Lemon example parses mathematical expressions. Finally, the document shows how to combine a Ragel lexer and Lemon parser to build a calculator application that can evaluate expressions.
The document describes how to search directories and files using the File and Directory classes in C#. It defines a regular expression to match file extensions and stores the number of files found for each extension. The program recursively searches all subdirectories, counts the number of files for each extension, and outputs a summary of the results. It also checks for and allows deleting any backup (.bak) files found.
This document provides an introduction to basic electronics concepts including electricity, voltage, current, resistance, LEDs, Ohm's law, and capacitors. It covers the following key points in 3 sentences:
The document defines basic concepts of electricity including how electrons flow in conductors to create currents, and defines voltage and current. It explains how voltage, current, and resistance are related by Ohm's law and how to measure these quantities using a multimeter. Various circuit components such as LEDs, resistors, capacitors, and breadboards are introduced along with exercises to apply concepts of series and parallel circuits.
The document describes object-oriented programming concepts like classes, objects, encapsulation, and properties. It provides code examples of a Time class that encapsulates time data and provides methods to work with it. The Time class uses properties to safely access private member variables for hour, minute and second. Constructors are demonstrated that initialize Time objects with different parameters.
The document discusses various graphical user interface controls in C#, including menus, link labels, list boxes, combo boxes, tree views, and tab controls. It provides code examples to demonstrate how to implement menus with options to change font colors and styles, as well as link labels that link to other programs or files when clicked. Event handlers are used to handle user interactions with the controls.
Hang Son Doong cave in Vietnam is the largest cave in the world. Discovered in 1991 by Ho-Khanh, it wasn't until 2009 when British scientists surveyed it that its massive size was known. One of its caverns could fit an entire New York City block and it holds a river and jungle inside. National Geographic documented the cave in 2010, revealing its chambers that are over 5 km long, 200m high, and 150m wide, making it twice the size of the previous largest cave.
The document discusses object-oriented programming concepts like inheritance, base classes, and derived classes. It provides code examples to illustrate inheritance relationships between classes like Point, Circle, and Cylinder. The code defines base classes like Point and derived classes like Circle that inherit properties and methods from their base classes. Tests are provided to create objects from derived classes and demonstrate inherited functionality.
The document outlines control structures in programming, including counter-controlled repetition, the for loop structure, the switch multiple-selection structure, and the do/while repetition structure. It provides code examples to demonstrate these structures, including initializing and incrementing counters, using break and continue statements to alter loop flow, and displaying output.
Everything You Always Wanted To Know About XML But Were Afraid To AskRichard Davis
Short internal XML course (2003). Interesting to note that RSS doesn't feature - hadn't quite hoved into our view at that point. Also no mention of OxygenXML - was I really not using it then? Seem to have been using it forever.
1) The document discusses expanding tree nodes in a Tree control by using the expandItem() method when the tree first opens.
2) It also discusses creating a subclass of Tree that can handle ItemPendingErrors by leveraging code from the AdvancedDataGrid and HierarchicalCollectionView.
3) An example code is provided to expand tree nodes programmatically using parameters passed to the application.
This document summarizes a presentation about manipulating and transforming Notes database design elements using DXL (Domino XML). It discusses exporting Notes databases to DXL, manipulating the DXL using Java/LotusScript/XSLT, and importing the modified DXL back into Notes. It also describes tools like DXLStudio that can be used to work with DXL from Java programs or the command line.
This document provides an introduction to JavaScript scripting. It discusses how JavaScript was originally created by Netscape to enhance web page functions and displays. It then presents some simple JavaScript programs to print text on a web page using methods like document.write() and document.writeln(). The programs demonstrate using variables, data types, operators, and conditional statements.
This document provides an introduction to JavaScript scripting. It discusses how JavaScript was originally created by Netscape to enhance web page functions and displays. It then presents some simple JavaScript programs to print text on a web page using methods like document.write() and document.writeln(). It also covers using variables, arithmetic operators, and conditional statements with relational operators in JavaScript.
This document discusses methods for debugging and handling errors when processing DITA documents with the DITA Open Toolkit (DITA-OT). It provides tips for redirecting output to log files, mapping code to output, speeding up debugging time, and using the merged XML file. It also discusses the differences between debugging and error handling, default and custom error handling options in DITA-OT, and tips for creating error messages.
1. The document discusses significant characteristics that need to be extracted from digital files to enable their long-term preservation and processing.
2. It describes solutions like the PRONOM and DROID formats registries, and the XCL extractor that can identify file formats and extract characteristics in a standardized way.
3. The document argues that automating characteristic extraction is necessary when dealing with large numbers of files, as it can save significant time compared to manual processing.
The document discusses XML namespaces and XML schemas. It provides examples of using namespaces to differentiate between similarly named elements, such as <highschool:subject> and <medicine:subject>. It also compares defining an XML document using a DTD versus using an XML schema, and provides a sample schema for defining book information. Key differences between "ref" and "type" attributes in schemas are explained using an employee example.
The document provides an overview of the Struts 2 framework, including its architecture, features, and configuration. Some key points:
- Struts 2 is an MVC framework that uses interceptors, actions, and results. It improves on Struts 1 with a cleaner architecture, annotations/XML configuration, and integration with other frameworks like Spring.
- Features include interceptors for pre/post processing, the value stack for request data, OGNL for data access, tag libraries, validation, internationalization support, and AJAX capabilities via Dojo integration.
- Configuration can be done via XML or annotations. Actions map requests to classes/methods, and results define views. Common features like validation are easily
The document discusses using the XML::XSH2 tool in Perl to process XML documents, describing how it allows working with XML using XPath queries and verbs to navigate, select, and transform XML content. Examples are provided of using XML::XSH2 to count elements, copy content between XML files, and convert between XML formats like transforming XML into HTML.
This document provides an introduction to XML Path Language (XPath), which is a syntax for locating information in an XML document. It describes the different node types in an XML document and XPath tree, such as element nodes, attribute nodes, and text nodes. It also explains some basic XPath concepts like axes, node tests, and location paths that allow navigating the XPath tree using steps separated by axes and node tests. Some examples of XPath functions and operators for manipulating node sets returned from location paths are also presented. Finally, it provides sample XML documents and uses XPath to select nodes and extract information from them.
The document discusses different XML parsers in Java including DOM, SAX, and StAX. DOM represents the XML document as an in-memory tree which allows flexible processing but uses more memory. SAX is event-driven and reads the XML sequentially using less memory. StAX is similar to SAX but simplified and "pull"-based where the developer manually navigates elements. The document also covers using JAXP for XML processing independence and the key classes involved in DOM and StAX parsing.
The document discusses using Sinatra and Datamapper to create web applications that store and retrieve data. It provides instructions on setting up a Sinatra app with Datamapper, defining a data model using classes, and storing, retrieving, updating and deleting data in YAML files. Examples are given for creating forms to store data, retrieving all data entries or a specific entry, and updating or deleting entries. The final assignment is to build a web app that uses these concepts.
This document provides an overview of DOM and SAX, two common XML APIs in Java. It describes the key differences between DOM and SAX, including that DOM builds an in-memory tree representation, while SAX parses the XML as a stream of events. The document also provides code examples for using SAX to parse XML and extract data, and examples of how to access and manipulate DOM trees after parsing XML.
Using REST and XML Builder for legacy XMLKeith Pitty
The document discusses using the XML Builder gem to generate XML in a legacy format when the default to_xml method does not meet needs. It shows how to create a presenter object to encapsulate the logic for building the XML, and use XML Builder in the view to generate the XML according to the legacy format, providing an alternative to to_xml for complex or custom XML generation needs.
The document provides an introduction and overview of using XSLT (eXtensible Stylesheet Language Transformations) with PHP4 to transform XML documents. It discusses XML basics, introduces XSLT and provides examples of using PHP's XSLT functions to apply XSL stylesheets to XML documents. It also covers more advanced XSLT topics like templates, location paths, control elements, and discusses some drawbacks of using XSLT.
The document discusses issues with the current XML Encryption Processing Rules that require encrypted elements to be replaced during encryption and decryption. This is too restrictive and prevents certain application scenarios. The document proposes allowing encrypted elements to be returned without replacing the source XML, which would provide more flexibility for application APIs. It provides examples of how the current rules prevent useful scenarios like encrypting elements for a SOAP message or decrypting without modifying the encrypted source document.
WML is a markup language used for displaying pages on mobile devices. It uses decks and cards, where a deck contains one or more cards and the user moves between cards. Key features of WML include support for text, images, user input, navigation between cards, and optimization for narrowband networks. It supports common elements like anchors, inputs, selections, and timers to refresh or navigate pages.
The document provides an overview of XML basics including:
- XML stands for Extensible Markup Language and is used to carry data, not display it. Users define their own tags.
- XML documents must have an XML declaration specifying the version and encoding. They must also have a root element containing other properly nested elements.
- Namespaces are used to avoid conflicts when mixing XML from different sources by prefixing elements.
- CDATA and PCDATA sections define how character data is handled within XML elements.
- Documents are considered well-formed if they follow XML syntax rules and valid if they also conform to DTD rules.
The document discusses implementing flagging and change tracking in DITA documents. It provides an overview of filtering and describes how to flag content based on attributes like product, audience and platform using a DITAVAL file. It also discusses using revision properties to flag changes and provides XML code samples.
This document outlines key concepts related to data structures including linked lists, stacks, queues, and trees. It provides code examples of a Node class that is self-referential, allowing objects to link to one another. A LinkedListLibrary class is defined, with methods for inserting and removing nodes from linked lists. A ListTest class tests the functionality of the List class.
The document discusses accessibility in web development and software applications. It covers regulations and guidelines for accessibility from the Web Accessibility Initiative (WAI) and other organizations. It also provides examples of implementing accessibility in Visual Studio .NET, C#, XHTML, and Microsoft Windows, including features for visual impairments, hearing impairments, and mobility issues. Specific techniques discussed include adding alt text for images, proper use of headings and structure, keyboard shortcuts, screen reading support, font size adjustments, and more.
The document discusses accessibility in web development and software applications. It covers topics like web accessibility guidelines, providing alternatives for images, maximizing readability in structures, accessibility in Visual Studio .NET, C#, XHTML tables and frames, and accessibility tools. Code examples are provided to demonstrate making applications more accessible for people with disabilities.
The document discusses client-server networking using both stream sockets and datagrams. It provides code examples for a server and client application that allow text-based communication using stream sockets, establishing a connection between the two. It also gives an example of a connectionless server and client that can send and receive datagrams containing byte arrays to simulate a chat. The server waits for packets and displays the contents, then echoes the data back to the client.
This document outlines a chapter about ASP.NET and web services. It includes code for a web service called HugeInteger that performs operations on large integers. The HugeInteger service exposes methods like Add, Subtract, Bigger etc through SOAP over HTTP. It shows how to publish web services, add service references to projects, and invoke web service methods from a client application.
This chapter discusses ASP.NET web forms and controls. It introduces the system architecture of web applications with different tiers. It then demonstrates creating a simple web form application in Visual Studio that displays the current time using labels and setting properties in the code-behind file. The application is run locally and the generated HTML is shown.
The document outlines how to connect to and query an Access database using ADO.NET in C#. It describes creating a TableDisplay form with a DataGrid to display query results. The form initializes a DataSet and OleDbDataAdapter to retrieve data from the Authors table and bind it to the DataGrid. It also configures OleDbCommands for selecting, inserting, updating, and deleting data.
The document discusses graphics and media capabilities in .NET, including graphics contexts, colors, fonts, and images. It covers creating graphics objects, setting colors using RGB values or names, constructing fonts and accessing font metrics, and loading/displaying images. Code examples are provided to demonstrate these graphics and font capabilities.
The document outlines the key topics covered in Chapter 15 on strings and characters in C#, including fundamentals of characters and strings, string constructors, using the string indexer and length property, comparing strings, and using methods like StartsWith and EndsWith. Code examples are provided to demonstrate using features like the string indexer, Length property, CopyTo method, comparing strings with Equals and CompareTo, and checking if a string starts or ends with a substring.
The document describes multithreading concepts in .NET including thread states, priorities, synchronization, and the producer-consumer relationship. It provides code examples to demonstrate threading without and with synchronization. Key points covered include allowing concurrent execution with threads, thread life cycles and states, using monitors for synchronization, and ensuring proper communication between producer and consumer threads.
This document provides an outline and overview of Chapter 12 which covers graphical user interface (GUI) concepts in Windows Forms. The chapter introduces GUI components like windows, controls, properties, events and event handling. It describes common controls like labels, text boxes, buttons and how to set properties, handle events, and lay out controls on a form. Code examples are provided to demonstrate creating a simple form with a textbox, label and button to display text on a label when a button is clicked.
This document discusses exception handling in C# and .NET. It provides examples of try/catch blocks, the different exception classes in .NET, and how to access exception properties like Message and StackTrace. Code samples are given that demonstrate throwing, catching, and rethrowing exceptions. Finally blocks are also discussed and shown to always execute even if an exception occurs.
The document discusses object-oriented programming concepts like polymorphism. It includes:
- An introduction to polymorphism and how it allows programs to handle related classes generically and be easily extensible.
- Examples of polymorphism including a shape hierarchy with classes like Quadrilateral, Rectangle, etc. and a space object hierarchy with classes that all implement a DrawYourself method.
- Details about abstract classes and how they provide base classes that concrete classes inherit from while requiring the concrete classes to implement abstract methods and properties.
- A case study demonstrating inheritance and polymorphism using abstract base class Shape and concrete classes Point2, Circle2, and Cylinder2 that inherit from Shape.
The document outlines key concepts about arrays including:
- Declaring and allocating arrays
- Initializing arrays with initializer lists or dynamically with 'new'
- Accessing array elements using indexes/subscripts
- Common array operations like totaling elements, creating histograms, and using arrays as counters
It provides code examples demonstrating initializing arrays, summing array elements, creating a histogram to display array data, and using arrays as counters in a dice rolling simulation program.
The document outlines a chapter on methods in C#. It discusses key concepts like defining methods, passing arguments by value vs reference, and using built-in classes like Math. It provides examples of methods that square integers, find the maximum of 3 numbers, and demonstrate passing by reference and out parameters.
The document outlines control structures in programming including algorithms, pseudocode, selection structures like if/else, repetition structures like while loops, and case studies applying these concepts. Key topics are counter-controlled and sentinel-controlled repetition for loops, and nesting control structures with if statements inside loops. Examples in C# demonstrate accumulating values in loops and nested if/else statements.
This document outlines the key concepts covered in Chapter 3 of an introduction to C# programming textbook. It discusses simple programs that print text, perform basic math operations, and make decisions using relational operators. Code examples are provided to demonstrate how to write, compile, and run simple C# console applications and use basic programming elements like variables, methods, and conditional statements.
The document provides an overview of the Visual Studio .NET integrated development environment (IDE). It describes the main interface elements like the menu bar, toolbar, solution explorer, toolbox and properties window. It then demonstrates how to create a simple project in Visual Studio .NET that displays text in a label and an image in a picture box without writing any code, using the drag and drop features of the IDE.
The document provides an overview of computers, operating systems, programming languages, the internet, and Microsoft .NET. It discusses the evolution of computers from early mainframes to personal computers and networks. It covers the development of operating systems, languages like C, C++, Java and C#, and web technologies like HTML, XML and the World Wide Web. It also summarizes Microsoft's .NET framework and how it allows applications to be developed in any .NET compatible language and run across platforms using the Common Language Runtime.
The document outlines key concepts about data structures including linked lists, stacks, queues, and trees. It provides code examples for a Node class that is self-referential, allowing objects to link to each other. It also includes a List class that implements basic linked list functionality through methods like InsertAtFront, InsertAtBack, RemoveFromFront, and RemoveFromBack. The code examples demonstrate how to create and manipulate linked lists through a List object.
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/building-and-scaling-ai-applications-with-the-nx-ai-manager-a-presentation-from-network-optix/
Robin van Emden, Senior Director of Data Science at Network Optix, presents the “Building and Scaling AI Applications with the Nx AI Manager,” tutorial at the May 2024 Embedded Vision Summit.
In this presentation, van Emden covers the basics of scaling edge AI solutions using the Nx tool kit. He emphasizes the process of developing AI models and deploying them globally. He also showcases the conversion of AI models and the creation of effective edge AI pipelines, with a focus on pre-processing, model conversion, selecting the appropriate inference engine for the target hardware and post-processing.
van Emden shows how Nx can simplify the developer’s life and facilitate a rapid transition from concept to production-ready applications.He provides valuable insights into developing scalable and efficient edge AI solutions, with a strong focus on practical implementation.
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceIndexBug
Imagine a world where machines not only perform tasks but also learn, adapt, and make decisions. This is the promise of Artificial Intelligence (AI), a technology that's not just enhancing our lives but revolutionizing entire industries.
UiPath Test Automation using UiPath Test Suite series, part 6DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 6. In this session, we will cover Test Automation with generative AI and Open AI.
UiPath Test Automation with generative AI and Open AI webinar offers an in-depth exploration of leveraging cutting-edge technologies for test automation within the UiPath platform. Attendees will delve into the integration of generative AI, a test automation solution, with Open AI advanced natural language processing capabilities.
Throughout the session, participants will discover how this synergy empowers testers to automate repetitive tasks, enhance testing accuracy, and expedite the software testing life cycle. Topics covered include the seamless integration process, practical use cases, and the benefits of harnessing AI-driven automation for UiPath testing initiatives. By attending this webinar, testers, and automation professionals can gain valuable insights into harnessing the power of AI to optimize their test automation workflows within the UiPath ecosystem, ultimately driving efficiency and quality in software development processes.
What will you get from this session?
1. Insights into integrating generative AI.
2. Understanding how this integration enhances test automation within the UiPath platform
3. Practical demonstrations
4. Exploration of real-world use cases illustrating the benefits of AI-driven test automation for UiPath
Topics covered:
What is generative AI
Test Automation with generative AI and Open AI.
UiPath integration with generative AI
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Infrastructure Challenges in Scaling RAG with Custom AI modelsZilliz
Building Retrieval-Augmented Generation (RAG) systems with open-source and custom AI models is a complex task. This talk explores the challenges in productionizing RAG systems, including retrieval performance, response synthesis, and evaluation. We’ll discuss how to leverage open-source models like text embeddings, language models, and custom fine-tuned models to enhance RAG performance. Additionally, we’ll cover how BentoML can help orchestrate and scale these AI components efficiently, ensuring seamless deployment and management of RAG systems in the cloud.
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slackshyamraj55
Discover the seamless integration of RPA (Robotic Process Automation), COMPOSER, and APM with AWS IDP enhanced with Slack notifications. Explore how these technologies converge to streamline workflows, optimize performance, and ensure secure access, all while leveraging the power of AWS IDP and real-time communication via Slack notifications.
Driving Business Innovation: Latest Generative AI Advancements & Success StorySafe Software
Are you ready to revolutionize how you handle data? Join us for a webinar where we’ll bring you up to speed with the latest advancements in Generative AI technology and discover how leveraging FME with tools from giants like Google Gemini, Amazon, and Microsoft OpenAI can supercharge your workflow efficiency.
During the hour, we’ll take you through:
Guest Speaker Segment with Hannah Barrington: Dive into the world of dynamic real estate marketing with Hannah, the Marketing Manager at Workspace Group. Hear firsthand how their team generates engaging descriptions for thousands of office units by integrating diverse data sources—from PDF floorplans to web pages—using FME transformers, like OpenAIVisionConnector and AnthropicVisionConnector. This use case will show you how GenAI can streamline content creation for marketing across the board.
Ollama Use Case: Learn how Scenario Specialist Dmitri Bagh has utilized Ollama within FME to input data, create custom models, and enhance security protocols. This segment will include demos to illustrate the full capabilities of FME in AI-driven processes.
Custom AI Models: Discover how to leverage FME to build personalized AI models using your data. Whether it’s populating a model with local data for added security or integrating public AI tools, find out how FME facilitates a versatile and secure approach to AI.
We’ll wrap up with a live Q&A session where you can engage with our experts on your specific use cases, and learn more about optimizing your data workflows with AI.
This webinar is ideal for professionals seeking to harness the power of AI within their data management systems while ensuring high levels of customization and security. Whether you're a novice or an expert, gain actionable insights and strategies to elevate your data processes. Join us to see how FME and AI can revolutionize how you work with data!
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
GraphRAG for Life Science to increase LLM accuracyTomaz Bratanic
GraphRAG for life science domain, where you retriever information from biomedical knowledge graphs using LLMs to increase the accuracy and performance of generated answers
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc
How does your privacy program stack up against your peers? What challenges are privacy teams tackling and prioritizing in 2024?
In the fifth annual Global Privacy Benchmarks Survey, we asked over 1,800 global privacy professionals and business executives to share their perspectives on the current state of privacy inside and outside of their organizations. This year’s report focused on emerging areas of importance for privacy and compliance professionals, including considerations and implications of Artificial Intelligence (AI) technologies, building brand trust, and different approaches for achieving higher privacy competence scores.
See how organizational priorities and strategic approaches to data security and privacy are evolving around the globe.
This webinar will review:
- The top 10 privacy insights from the fifth annual Global Privacy Benchmarks Survey
- The top challenges for privacy leaders, practitioners, and organizations in 2024
- Key themes to consider in developing and maintaining your privacy program
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!SOFTTECHHUB
As the digital landscape continually evolves, operating systems play a critical role in shaping user experiences and productivity. The launch of Nitrux Linux 3.5.0 marks a significant milestone, offering a robust alternative to traditional systems such as Windows 11. This article delves into the essence of Nitrux Linux 3.5.0, exploring its unique features, advantages, and how it stands as a compelling choice for both casual users and tech enthusiasts.
Unlocking Productivity: Leveraging the Potential of Copilot in Microsoft 365, a presentation by Christoforos Vlachos, Senior Solutions Manager – Modern Workplace, Uni Systems
1. Chapter 18 – Extensible Markup Language (XML) Outline 18.1 Introduction 18.2 XML Documents 18.3 XML Namespaces 18.4 Document Object Model (DOM) 18.5 Document Type Definitions (DTDs), Schemas and Validation 18.5.1 Document Type Definitions 18.5.2 Microsoft XML Schemas 18.6 Extensible Stylesheet Language and XslTransform 18.7 Microsoft BizTalk
2.
3.
4. article.xml 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.1: article.xml --> 4 <!-- Article structured with XML --> 5 6 <article> 7 8 <title> Simple XML </title> 9 10 <date> December 6, 2001 </date> 11 12 <author> 13 <firstName> Tem </firstName> 14 <lastName> Nieto </lastName> 15 </author> 16 17 <summary> XML is pretty easy. </summary> 18 19 <content> In this chapter, we present a wide variety of examples 20 that use XML 21 </content> 22 23 </article> Optional XML declaration identifying document type version information parameter specify version of XML being used Example of start tag Examples of end tag Root element Example of character data
5. 18.2 XML Documents minus sign Fig. 18.2 article.xml displayed by Internet Explorer (part 1).
6. 18.2 XML Documents Fig. 18.2 article.xml displayed by Internet Explorer (part 2). plus sign
7. letter.xml 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.3: letter.xml --> 4 <!-- Business letter formatted with XML --> 5 6 <letter> 7 <contact type = "from" > 8 <name> Jane Doe </name> 9 <address1> Box 12345 </address1> 10 <address2> 15 Any Ave. </address2> 11 <city> Othertown </city> 12 <state> Otherstate </state> 13 <zip> 67890 </zip> 14 <phone> 555-4321 </phone> 15 <flag gender = "F" /> 16 </contact> 17 18 <contact type = "to" > 19 <name> John Doe </name> 20 <address1> 123 Main St. </address1> 21 <address2></address2> 22 <city> Anytown </city> 23 <state> Anystate </state> 24 <zip> 12345 </zip> 25 <phone> 555-1234 </phone> 26 <flag gender = "M" /> 27 </contact> 28 Child element of root element letter element has attribute type with value “from” The person who sent the letter The recipient of the letter Empty element flag
8. letter.xml 29 <salutation> Dear Sir: </salutation> 30 31 <paragraph> It is our privilege to inform you about our new 32 database managed with <technology> XML </technology> . This 33 new system allows you to reduce the load on 34 your inventory list server by having the client machine 35 perform the work of sorting and filtering the data. 36 </paragraph> 37 38 <paragraph> Please visit our Web site for availability 39 and pricing. 40 </paragraph> 41 <closing> Sincerely </closing> 42 <signature> Ms. Doe </signature> 43 </letter> Other expected parts of a typical letter
9.
10. namespace.xml Program Output 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.4: namespace.xml --> 4 <!-- Demonstrating namespaces --> 5 6 <text:directory xmlns:text = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo" > 8 9 <text:file filename = "book.xml" > 10 <text:description> A book list </text:description> 11 </text:file> 12 13 <image:file filename = "funny.jpg" > 14 <image:description> A funny picture </image:description> 15 <image:size width = "200" height = "100" /> 16 </image:file> 17 18 </text:directory> Attribute xmlns to create two namespace prefixes Universal Resource Identifier that uniquely identifies the namespace Prefix text to qualify elements file and description as belonging to namespace urn:deitel:textInfo by applying namespace prefix text Apply namespace prefix image to elements file , description and size Parser never visits these URI’s, they are used to differentiate names
11. defaultnamespace.xml Program Output 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.5: defaultnamespace.xml --> 4 <!-- Using default namespaces --> 5 6 <directory xmlns = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo" > 8 9 <file filename = "book.xml" > 10 <description> A book list </description> 11 </file> 12 13 <image:file filename = "funny.jpg" > 14 <image:description> A funny picture </image:description> 15 <image:size width = "200" height = "100" /> 16 </image:file> 17 18 </directory> Declare a default namespace using attribute xmlns with URI as its value No longer prefix file or description with text file prefixed with image to indicate it is in the namespace urn:deitel:imageInfo and not the default namespace
12.
13. 18.4 Document Object Model (DOM) Fig. 18.6 Tree structure for Fig. 18.1. article firstName contents summary author date title lastName
14. XmlReaderTest.cs 1 // Fig. 18.7: XmlReaderTest.cs 2 // Reading an XML document. 3 4 using System; 5 using System.Windows.Forms; 6 using System.Xml; 7 8 public class XmlReaderTest : System.Windows.Forms.Form 9 { 10 private System.Windows.Forms.TextBox outputTextBox; 11 private System.ComponentModel.Container components = null ; 12 13 public XmlReaderTest() 14 { 15 InitializeComponent(); 16 17 // reference to "XML document" 18 XmlDocument document = new XmlDocument(); 19 document.Load( "article.xml" ); 20 21 // create XmlNodeReader for document 22 XmlNodeReader reader = new XmlNodeReader( document ); 23 24 // show form before outputTextBox is populated 25 this .Show(); 26 27 // tree depth is -1, no indentation 28 int depth = -1 ; 29 Reference namespace that contains the XML classes used for this example Create a new XmlDocument object Parse and load article.xml into variable document by calling XmlDocument method Load Create an XmlNodeReader that can read one node at a time from document Variable depth keeps track of the number of tab characters needed to display the current element
15. XmlReaderTest.cs 30 // display each node's content 31 while ( reader.Read() ) 32 { 33 switch ( reader.NodeType ) 34 { 35 // if Element, display its name 36 case XmlNodeType. Element : 37 38 // increase tab depth 39 depth++; 40 TabOutput( depth ); 41 outputTextBox.Text += "<" + reader.Name + ">" + 42 "" ; 43 44 // if empty element, decrease depth 45 if ( reader.IsEmptyElement ) 46 depth--; 47 48 break ; 49 50 // if Comment, display it 51 case XmlNodeType. Comment : 52 TabOutput( depth ); 53 outputTextBox.Text += 54 "<!--" + reader.Value + "-->" ; 55 break ; 56 57 // if Text, display it 58 case XmlNodeType. Text : 59 TabOutput( depth ); 60 outputTextBox.Text += "" + reader.Value + 61 "" ; 62 break ; 63 Loop to read each node in the DOM tree switch statement to process the node type If the node is an element, use Name property to display it between angle brackets If the node is a comment, use Value property to display the comment between comment notation tags If the node contains text, use Value property to display it
16. XmlReaderTest.cs 64 // if XML declaration, display it 65 case XmlNodeType. XmlDeclaration : 66 TabOutput( depth ); 67 outputTextBox.Text += "<?" + reader.Name + " " 68 + reader.Value + " ?>" ; 69 break ; 70 71 // if EndElement, display it and decrement depth 72 case XmlNodeType. EndElement : 73 TabOutput( depth ); 74 outputTextBox.Text += "</" + reader.Name 75 + ">" ; 76 depth--; 77 break ; 78 } // end switch statement 79 } // end while loop 80 } // End XmlReaderTest constructor 81 82 // insert tabs 83 private void TabOutput( int number ) 84 { 85 for ( int i = 0 ; i < number; i++ ) 86 outputTextBox.Text += "" ; 87 } // end TabOutput 88 89 // Windows Form Designer generated code 90 91 [STAThread] 92 static void Main() 93 { 94 Application.Run( new XmlReaderTest() ); 95 } // end Main 96 } // end XmlReaderTest If the node is an XML declaration, use Name and Value properties to display the declaration If the node is the end of an element, display the close tag using Name property and decrement depth Method TabOutput outputs a specified number of tab characters
18. XmlDom.cs 1 // Fig. 18.8: XmlDom.cs 2 // Demonstrates DOM tree manipulation. 3 4 using System; 5 using System.Windows.Forms; 6 using System.Xml; 7 using System.IO; 8 using System.CodeDom.Compiler; // contains TempFileCollection 9 10 // Class XmlDom demonstrates the DOM 11 public class XmlDom : System.Windows.Forms.Form 12 { 13 private System.Windows.Forms.Button buildButton; 14 private System.Windows.Forms.Button printButton; 15 private System.Windows.Forms.TreeView xmlTreeView; 16 private System.Windows.Forms.TextBox consoleTextBox; 17 private System.Windows.Forms.Button resetButton; 18 private System.ComponentModel.Container components = null ; 19 20 private XmlDocument source; // reference to "XML document" 21 22 // reference copy of source's "XML document" 23 private XmlDocument copy; 24 25 private TreeNode tree; // TreeNode reference 26 27 public XmlDom() 28 { 29 InitializeComponent(); 30 31 // create XmlDocument and load letter.xml 32 source = new XmlDocument(); 33 source.Load( "letter.xml" ); 34 Assign new XmlDocument object to reference source Method Load to parse and load letter.xml Object tree of type TreeNode to represent each node in the tree
19. XmlDom.cs 35 // initialize references to null 36 copy = null ; 37 tree = null ; 38 } // end XmlDom 39 40 [STAThread] 41 static void Main() 42 { 43 Application.Run( new XmlDom() ); 44 } 45 46 // event handler for buildButton click event 47 private void buildButton_Click( object sender, 48 System.EventArgs e ) 49 { 50 // determine if copy has been built already 51 if ( copy != null ) 52 return ; // document already exists 53 54 // instantiate XmlDocument and TreeNode 55 copy = new XmlDocument(); 56 tree = new TreeNode(); 57 58 // add root node name to TreeNode and add 59 // TreeNode to TreeView control 60 tree.Text = source.Name; // assigns #root 61 xmlTreeView.Nodes.Add( tree ); 62 63 // build node and tree hierarchy 64 BuildTree( source, copy, tree ); 65 66 printButton.Enabled = true ; 67 resetButton.Enabled = true ; 68 } // end buildButton_Click Assign to tree ’s Text property the name of the root in source Insert tree into TreeView control’s node list via method Add Copy XMLDocument referenced by source and update TreeView
20. XmlDom.cs 69 70 // event handler for printButton click event 71 private void printButton_Click( object sender, 72 System.EventArgs e ) 73 { 74 // exit if copy does not reference an XmlDocument 75 if ( copy == null ) 76 return ; 77 78 // create temporary XML file 79 TempFileCollection file = new TempFileCollection(); 80 81 // create file that is deleted at program termination 82 file.AddExtension( "xml" , false ); 83 string [] filename = new string [ 1 ]; 84 file.CopyTo( filename, 0 ); 85 86 // write XML data to disk 87 XmlTextWriter writer = new XmlTextWriter( filename[ 0 ], 88 System.Text.Encoding. UTF8 ); 89 copy.WriteTo( writer ); 90 writer.Close(); 91 92 // parse and load temporary XML document 93 XmlTextReader reader = new XmlTextReader( filename[ 0 ] ); 94 95 // read, format and display data 96 while ( reader.Read() ) 97 { 98 if ( reader.NodeType == XmlNodeType. EndElement ) 99 consoleTextBox.Text += "/" ; If copy does not reference an XmlDocument , exit the method Create a TempFileCollection that will be used to store one temporary file Add a file with the .xml extension and specify that it should be deleted after use Use method CopyTo to copy the names of all the files in the collection to the string array filename Create an XmlTextWriter that writes to the file whose name is in the first element of filename array (the one file added to the collection on line 82) Write all the contents of copy to writer Create an XmlTextReader for the temporary file Read all the data Print a slash if the node is an the end of an element
21. XmlDom.cs 100 101 if ( reader.Name != String. Empty ) 102 consoleTextBox.Text += reader.Name + "" ; 103 104 if ( reader.Value != String. Empty ) 105 consoleTextBox.Text += "" + reader.Value + 106 "" ; 107 } // end while 108 109 reader.Close(); 110 } // end printButton_Click 111 112 // handle resetButton click event 113 private void resetButton_Click( object sender, 114 System.EventArgs e ) 115 { 116 // remove TreeView nodes 117 if ( tree != null ) 118 xmlTreeView.Nodes.Remove( tree ); 119 120 xmlTreeView.Refresh(); // force TreeView update 121 122 // delete XmlDocument and tree 123 copy = null ; 124 tree = null ; 125 126 consoleTextBox.Text = "" ; // clear text box 127 128 printButton.Enabled = false ; 129 resetButton.Enabled = false ; 130 131 } // end resetButton_Click 132 Print the Name of the node if there is one Print the Value of the node if there is one If the TreeView object has been created, remove tree from its set of nodes Force the TreeView to refresh its display Set copy and tree references to null
22. XmlDom.cs 133 // construct DOM tree 134 private void BuildTree( XmlNode xmlSourceNode, 135 XmlNode document, TreeNode treeNode ) 136 { 137 // create XmlNodeReader to access XML document 138 XmlNodeReader nodeReader = new XmlNodeReader( 139 xmlSourceNode ); 140 141 // represents current node in DOM tree 142 XmlNode currentNode = null ; 143 144 // treeNode to add to existing tree 145 TreeNode newNode = new TreeNode(); 146 147 // references modified node type for CreateNode 148 XmlNodeType modifiedNodeType; 149 150 while ( nodeReader.Read() ) 151 { 152 // get current node type 153 modifiedNodeType = nodeReader.NodeType; 154 155 // check for EndElement, store as Element 156 if ( modifiedNodeType == XmlNodeType. EndElement ) 157 modifiedNodeType = XmlNodeType. Element ; 158 159 // create node copy 160 currentNode = copy.CreateNode( modifiedNodeType, 161 nodeReader.Name, nodeReader.NamespaceURI ); 162 Reference to current location in tree Loop through each node in the tree Create node type containing a copy of the current nodeReader node type Create an XmlNode via method CreateNode of XmlDocument Set the node type to be XmlNodeType.Element if it is of type XmlNodeType.EndElement Create an XmlNodeReader to read from xmlSourceNode Reference to source node Reference to empty node which will contain the copy of the source XML document
23. XmlDom.cs 163 // build tree based on node type 164 switch ( nodeReader.NodeType ) 165 { 166 // if Text node, add its value to tree 167 case XmlNodeType. Text : 168 newNode.Text = nodeReader.Value; 169 treeNode.Nodes.Add( newNode ); 170 171 // append Text node value to currentNode data 172 ( ( XmlText ) currentNode ).AppendData( 173 nodeReader.Value ); 174 document.AppendChild( currentNode ); 175 break ; 176 177 // if EndElement, move up tree 178 case XmlNodeType. EndElement : 179 document = document.ParentNode; 180 treeNode = treeNode.Parent; 181 break ; 182 183 // if new element, add name and traverse tree 184 case XmlNodeType. Element : 185 186 // determine if element contains content 187 if ( !nodeReader.IsEmptyElement ) 188 { 189 // assign node text, add newNode as child 190 newNode.Text = nodeReader.Name; 191 treeNode.Nodes.Add( newNode ); 192 193 // set treeNode to last child 194 treeNode = newNode; Switch statement to determine node type, create and add node and update DOM tree If a text node then assign current node’s value Downcast currentNode to XmlText and append the node’s value If it is an end element, set document to its ParentNode property and the current node in the tree to its Parent property For element node types, if the current element contains content, add a node containing the content as a child to the current tree node
24. XmlDom.cs 195 196 document.AppendChild( currentNode ); 197 document = document.LastChild; 198 } 199 else // do not traverse empty elements 200 { 201 // assign NodeType string to newNode 202 newNode.Text = 203 nodeReader.NodeType.ToString(); 204 205 treeNode.Nodes.Add( newNode ); 206 document.AppendChild( currentNode ); 207 } 208 209 break ; 210 211 // all other types, display node type 212 default : 213 newNode.Text = nodeReader.NodeType.ToString(); 214 treeNode.Nodes.Add( newNode ); 215 document.AppendChild( currentNode ); 216 break ; 217 } // end switch 218 219 newNode = new TreeNode(); 220 } // end while 221 222 // update the TreeView control 223 xmlTreeView.ExpandAll(); 224 xmlTreeView.Refresh(); 225 226 } // end BuildTree 227 } // end XmlDom Add the current node as a child of document and set document to its last child If the node has no content, set the newNode Text property to be the type of the node. Add newNode to treeNode and add currentNode to document For all other node types, display the type of the node and update the copy Expand all the nodes and refresh the TreeView display
26. PathNavigator.cs 1 // Fig. 18.9: PathNavigator.cs 2 // Demonstrates Class XPathNavigator. 3 4 using System; 5 using System.Windows.Forms; 6 using System.Xml.XPath; // contains XPathNavigator 7 8 public class PathNavigator : System.Windows.Forms.Form 9 { 10 private System.Windows.Forms.Button firstChildButton; 11 private System.Windows.Forms.Button parentButton; 12 private System.Windows.Forms.Button nextButton; 13 private System.Windows.Forms.Button previousButton; 14 private System.Windows.Forms.Button selectButton; 15 private System.Windows.Forms.TreeView pathTreeViewer; 16 private System.Windows.Forms.ComboBox selectComboBox; 17 private System.ComponentModel.Container components = null ; 18 private System.Windows.Forms.TextBox selectTreeViewer; 19 private System.Windows.Forms.GroupBox navigateBox; 20 private System.Windows.Forms.GroupBox locateBox; 21 22 // navigator to traverse document 23 private XPathNavigator xpath; 24 25 // references document for use by XPathNavigator 26 private XPathDocument document; 27 28 // references TreeNode list used by TreeView control 29 private TreeNode tree; 30 31 public PathNavigator() 32 { 33 InitializeComponent(); 34
27. PathNavigator.cs 35 // load XML document 36 document = new XPathDocument( "sports.xml" ); 37 38 // create navigator 39 xpath = document.CreateNavigator(); 40 41 // create root node for TreeNodes 42 tree = new TreeNode(); 43 44 tree.Text = xpath.NodeType.ToString(); // #root 45 pathTreeViewer.Nodes.Add( tree ); // add tree 46 47 // update TreeView control 48 pathTreeViewer.ExpandAll(); 49 pathTreeViewer.Refresh(); 50 pathTreeViewer.SelectedNode = tree; // highlight root 51 } // end constructor 52 53 [STAThread] 54 static void Main() 55 { 56 Application.Run( new PathNavigator() ); 57 } 58 59 // traverse to first child 60 private void firstChildButton_Click( object sender, 61 System.EventArgs e ) 62 { 63 TreeNode newTreeNode; 64 Parse and load sports.xml into document Use method CreateNavigator to create an XPathNavigator that will allow navigation of document Initialize TreeView to contain the root element
28. PathNavigator.cs 65 // move to first child 66 if ( xpath.MoveToFirstChild() ) 67 { 68 newTreeNode = new TreeNode(); // create new node 69 70 // set node's Text property to either 71 // navigator's name or value 72 DetermineType( newTreeNode, xpath ); 73 74 // add node to TreeNode node list 75 tree.Nodes.Add( newTreeNode ); 76 tree = newTreeNode; // assign tree newTreeNode 77 78 // update TreeView control 79 pathTreeViewer.ExpandAll(); 80 pathTreeViewer.Refresh(); 81 pathTreeViewer.SelectedNode = tree; 82 } 83 else // node has no children 84 MessageBox.Show( "Current Node has no children." , 85 "" , MessageBoxButtons. OK , 86 MessageBoxIcon. Information ); 87 } 88 89 // traverse to node's parent on parentButton click event 90 private void parentButton_Click( object sender, 91 System.EventArgs e ) 92 { 93 // move to parent 94 if ( xpath.MoveToParent() ) 95 { 96 tree = tree.Parent; 97 98 // get number of child nodes, not including sub trees 99 int count = tree.GetNodeCount( false ); If move to first child was successful (via method MoveToFirstChild ) Call method DetermineType to set the new node’s Text property to either the navigator’s name (if an element) or value (otherwise) Add the new child node to tree ’s node collection and set tree to reference the child node If the node has no children display error message If move to parent was successful (via method MoveToParent ) Set count to the number of children the node has
29. PathNavigator.cs 100 101 // remove all children 102 tree.Nodes.Clear(); 103 104 // update TreeView control 105 pathTreeViewer.ExpandAll(); 106 pathTreeViewer.Refresh(); 107 pathTreeViewer.SelectedNode = tree; 108 } 109 else // if node has no parent (root node) 110 MessageBox.Show( "Current node has no parent." , "" , 111 MessageBoxButtons. OK , 112 MessageBoxIcon. Information ); 113 } 114 115 // find next sibling on nextButton click event 116 private void nextButton_Click( object sender, 117 System.EventArgs e ) 118 { 119 TreeNode newTreeNode = null , newNode = null ; 120 121 // move to next sibling 122 if ( xpath.MoveToNext() ) 123 { 124 newTreeNode = tree.Parent; // get parent node 125 126 newNode = new TreeNode(); // create new node 127 DetermineType( newNode, xpath ); 128 newTreeNode.Nodes.Add( newNode ); 129 130 // set current position for display 131 tree = newNode; 132 Iterate through loop count time and remove the first node (accessible via FirstNode property), thus removing all the node’s children If move to next sibling is successful (via method MoveToNext ) Create new node for the sibling and add it to the parent node Retrieve reference to parent node
30. PathNavigator.cs 133 // update TreeView control 134 pathTreeViewer.ExpandAll(); 135 pathTreeViewer.Refresh(); 136 pathTreeViewer.SelectedNode = tree; 137 } 138 else // node has no additional siblings 139 MessageBox.Show( "Current node is last sibling." , 140 "" , MessageBoxButtons. OK , 141 MessageBoxIcon. Information ); 142 } // end nextButton_Click 143 144 // get previous sibling on previousButton click 145 private void previousButton_Click( object sender, 146 System.EventArgs e ) 147 { 148 TreeNode parentTreeNode = null ; 149 150 // move to previous sibling 151 if ( xpath.MoveToPrevious() ) 152 { 153 parentTreeNode = tree.Parent; // get parent node 154 155 // delete current node 156 parentTreeNode.Nodes.Remove( tree ); 157 158 // move to previous node 159 tree = parentTreeNode.LastNode; 160 161 // update TreeView control 162 pathTreeViewer.ExpandAll(); 163 pathTreeViewer.Refresh(); 164 pathTreeViewer.SelectedNode = tree; 165 } If move to previous sibling is successful (via method MoveToPrevious ) Retrieve reference to parent node Remove current node (the last child) Set tree to reference the last child
31. PathNavigator.cs 166 else // if current node has no previous siblings 167 MessageBox.Show( "Current node is first sibling." , 168 "" , MessageBoxButtons. OK , 169 MessageBoxIcon. Information ); 170 } // end previousButton_Click 171 172 // process selectButton click event 173 private void selectButton_Click( object sender, 174 System.EventArgs e ) 175 { 176 XPathNodeIterator iterator; // enables node iteration 177 178 // get specified node from ComboBox 179 try 180 { 181 iterator = xpath.Select( selectComboBox.Text ); 182 DisplayIterator( iterator ); // print selection 183 } 184 185 // catch invalid expressions 186 catch ( System.ArgumentException argumentException ) 187 { 188 MessageBox.Show( argumentException.Message, 189 "Error" , MessageBoxButtons. OK , 190 MessageBoxIcon. Error ); 191 } 192 } // end selectButton_Click 193 194 // print values for XPathNodeIterator 195 private void DisplayIterator( XPathNodeIterator iterator ) 196 { 197 selectTreeViewer.Text = "" ; 198 Call method DisplayIterator to update selectTreeViewer Set the XPathNodeIterator to be the iterator for the node with the text the user selected from the ComboBox
32. PathNavigator.cs 199 // prints selected node's values 200 while ( iterator.MoveNext() ) 201 selectTreeViewer.Text += 202 iterator.Current.Value.Trim() 203 + "" ; 204 } // end DisplayIterator 205 206 // determine if TreeNode should display current node 207 // name or value 208 private void DetermineType( TreeNode node, 209 XPathNavigator xPath ) 210 { 211 // determine NodeType 212 switch ( xPath.NodeType ) 213 { 214 // if Element, get its name 215 case XPathNodeType. Element : 216 217 // get current node name, and remove whitespace 218 node.Text = xPath.Name.Trim(); 219 break ; 220 221 // obtain node values 222 default : 223 224 // get current node value and remove whitespace 225 node.Text = xPath.Value.Trim(); 226 break ; 227 228 } // end switch 229 } // end DetermineType 230 } // end PathNavigator If the node is an element, set the Text property of node to contain the name of the element If the node type is anything else, set the Text property of node to the Value of the XPathNavigator
39. letter.dtd 1 <!-- Fig. 18.12: letter.dtd --> 2 <!-- DTD document for letter.xml --> 3 4 <!ELEMENT letter ( contact+, salutation, paragraph+, 5 closing, signature ) > 6 7 <!ELEMENT contact ( name, address1, address2, city, state, 8 zip, phone, flag ) > 9 <!ATTLIST contact type CDATA #IMPLIED> 10 11 <!ELEMENT name ( #PCDATA ) > 12 <!ELEMENT address1 ( #PCDATA ) > 13 <!ELEMENT address2 ( #PCDATA ) > 14 <!ELEMENT city ( #PCDATA ) > 15 <!ELEMENT state ( #PCDATA ) > 16 <!ELEMENT zip ( #PCDATA ) > 17 <!ELEMENT phone ( #PCDATA ) > 18 <!ELEMENT flag EMPTY> 19 <!ATTLIST flag gender (M | F) "M" > 20 21 <!ELEMENT salutation ( #PCDATA ) > 22 <!ELEMENT closing ( #PCDATA ) > 23 <!ELEMENT paragraph ( #PCDATA ) > 24 <!ELEMENT signature ( #PCDATA ) > This ELEMENT element type declaration defines the rules for an element letter Element letter is defined to have one or more contact elements, one salutation element, one or more paragraph elements, a closing element and a signature element Definition for the contact element This ATTLIST element type declaration defines the type attribute for contact elements. The type attribute is of type CDATA (string not processed by the parser but passed to the application). Flag #IMPLIED specifies that the type attribute is not required. Flag #PCDATA specifies that the element consists of parsed character data (text with no markup) Keyword EMPTY specifies that the element cannot contain character data ( EMPTY elements are commonly used for their attributes)
40. letter2.xml 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.13: letter2.xml --> 4 <!-- Business letter formatted with XML --> 5 6 <!DOCTYPE letter SYSTEM "letter.dtd" > 7 8 <letter> 9 <contact type = "from" > 10 <name> Jane Doe </name> 11 <address1> Box 12345 </address1> 12 <address2> 15 Any Ave. </address2> 13 <city> Othertown </city> 14 <state> Otherstate </state> 15 <zip> 67890 </zip> 16 <phone> 555-4321 </phone> 17 <flag gender = "F" /> 18 </contact> 19 20 <contact type = "to" > 21 <name> John Doe </name> 22 <address1> 123 Main St. </address1> 23 <address2></address2> 24 <city> Anytown </city> 25 <state> Anystate </state> 26 <zip> 12345 </zip> 27 <phone> 555-1234 </phone> 28 <flag gender = "M" /> 29 </contact> 30 Specifies the location of the DTD file and the element ( letter ) to which the DTD is applied
41. letter2.xml 31 <salutation> Dear Sir: </salutation> 32 33 <paragraph> It is our privilege to inform you about our new 34 database managed with XML. This new system 35 allows you to reduce the load on your inventory list 36 server by having the client machine perform the work of 37 sorting and filtering the data. 38 </paragraph> 39 40 <paragraph> Please visit our Web site for availability 41 and pricing. 42 </paragraph> 43 <closing> Sincerely </closing> 44 <signature> Ms. Doe </signature> 45 </letter>
42. 18.5 Document Type Definitions (DTDs) Schemas and Validation Fig. 18.14 XML Validator used to validate an XML document.
43.
44. 18.5 Document Type Definitions (DTDs) Schemas and Validation Fig. 18.15 XML Validator displaying an error message.
45. bookxdr.xml 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.16: bookxdr.xml --> 4 <!-- XML file that marks up book data --> 5 6 <books xmlns = "x-schema:book.xdr" > 7 <book> 8 <title> C# How to Program </title> 9 </book> 10 11 <book> 12 <title> Java to Program, 4/e </title> 13 </book> 14 15 <book> 16 <title> Visual Basic .NET How to Program </title> 17 </book> 18 19 <book> 20 <title> Advanced Java 2 Platform How to Program </title> 21 </book> 22 23 <book> 24 <title> Python How to Program </title> 25 </book> 26 </books>
46. book.xdr 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.17: book.xdr --> 4 <!-- Schema document to which book.xml conforms --> 5 6 <Schema xmlns = "urn:schemas-microsoft-com:xml-data" > 7 <ElementType name = "title" content = "textOnly" 8 model = "closed" /> 9 10 <ElementType name = "book" content = "eltOnly" model = "closed" > 11 <element type = "title" minOccurs = "1" maxOccurs = "1" /> 12 </ElementType> 13 14 <ElementType name = "books" content = "eltOnly" model = "closed" > 15 <element type = "book" minOccurs = "0" maxOccurs = "*" /> 16 </ElementType> 17 </Schema> Keyword Schema signifies the beginning of the schema markup Namespace URI used by Microsoft Schemas Element ElementType used to define element title The content attribute specifies that this element is text-only Setting the model attribute to “closed” specifies that a conforming XML document can contain only elements defined in this Schema Setting content to “eltOnly” specifies that this element can contain mixed content (text and other elements) The element element within the ElementType element specifies that title is a child element of book Attributes minOccurs and maxOccurs are set to 1, indicating that the title element must occur exactly once in a book element Indicates that a books element can have any number of book elements
47.
48. bookxsd.xml 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.18: bookxsd.xml --> 4 <!-- Document that conforms to W3C XML Schema --> 5 6 <deitel:books xmlns:deitel = "http://www.deitel.com/booklist" > 7 <book> 8 <title> e-Business and e-Commerce How to Program </title> 9 </book> 10 <book> 11 <title> Python How to Program </title> 12 </book> 13 </deitel:books>
49. book.xsd 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.19: book.xsd --> 4 <!-- Simple W3C XML Schema document --> 5 6 <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" 7 xmlns:deitel = "http://www.deitel.com/booklist" 8 targetNamespace = "http://www.deitel.com/booklist" > 9 10 <xsd:element name = "books" type = "deitel:BooksType" /> 11 12 <xsd:complexType name = "BooksType" > 13 <xsd:sequence> 14 <xsd:element name = "book" type = "deitel:BookType" 15 minOccurs = "1" maxOccurs = "unbounded" /> 16 </xsd:sequence> 17 </xsd:complexType> 18 19 <xsd:complexType name = "BookType" > 20 <xsd:sequence> 21 <xsd:element name = "title" type = "xsd:string" /> 22 </xsd:sequence> 23 </xsd:complexType> 24 25 </xsd:schema> W3C XML Schema uses namespace URI http://www.w3.org/2001/XMLSchema Namespace for elements and attributes that this schema defines An example of complex type Simple type prohibited from containing attributes and child element
50.
51. ValidationTest.cs 1 // Fig. 18.20: ValidationTest.cs 2 // Validating XML documents against Schemas. 3 4 using System; 5 using System.Windows.Forms; 6 using System.Xml; 7 using System.Xml.Schema; // contains Schema classes 8 9 // determines XML document Schema validity 10 public class ValidationTest : System.Windows.Forms.Form 11 { 12 private System.Windows.Forms.ComboBox filesComboBox; 13 private System.Windows.Forms.Button validateButton; 14 private System.Windows.Forms.Label consoleLabel; 15 private System.ComponentModel.Container components = null ; 16 17 private XmlSchemaCollection schemas; // Schemas 18 private bool valid; // validation result 19 20 public ValidationTest() 21 { 22 InitializeComponent(); 23 24 valid = true ; // assume document is valid 25 26 // get Schema(s) for validation 27 schemas = new XmlSchemaCollection(); 28 schemas.Add( "book" , "book.xdr" ); 29 schemas.Add ( “http://www.deitel.com/booklist" , "book.xsd" ); 30 } // end constructor 31 32 // Visual Studio .NET generated code 33 Instantiate an XmlSchemaCollection schemas Use method Add to add a schema named book located in book.xdr to schema Add a W3C XML Schema
52. ValidationTest.cs 34 [STAThread] 35 static void Main() 36 { 37 Application.Run( new ValidationTest() ); 38 } // end Main 39 40 // handle validateButton click event 41 private void validateButton_Click( object sender, 42 System.EventArgs e ) 43 { 44 // get XML document 45 XmlTextReader reader = 46 new XmlTextReader( filesComboBox.Text ); 47 48 // get validator 49 XmlValidatingReader validator = 50 new XmlValidatingReader( reader ); 51 52 // assign Schema(s) 53 validator.Schemas.Add( schemas ); 54 55 // Microsoft XDR validation 56 validator.ValidationType = ValidationType. XDR ; 57 58 // register event handler for validation error(s) 59 validator.ValidationEventHandler += 60 new ValidationEventHandler( ValidationError ); 61 62 // validate document node-by-node 63 while ( validator.Read() ) ; // empty body 64 65 // check validation result 66 if ( valid ) 67 consoleLabel.Text = "Document is valid" ; 68 Create XmlReader for the file that the user selected from filesComboBox Add s the Schema collection referenced by Schemas to the Schemas property Each call to Read validates the next node in the document
53. ValidationTest.cs Program Output 69 valid = true ; // reset variable 70 71 // close reader stream 72 validator.Close(); 73 } // end validateButton_Click 74 75 // event handler for validation error 76 private void ValidationError( object sender, 77 ValidationEventArgs arguments ) 78 { 79 consoleLabel.Text = arguments.Message; 80 valid = false ; // validation failed 81 } // end ValidationError 82 } // end ValidationTest Called if document is invalid or an error occurs
54. Bookxsdfail.cs Program output 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.22: bookxsdfail.xml --> 4 <!-- Document that does not conforms to W3C Schema --> 5 6 <deitel:books xmlns:deitel = "http://www.deitel.com/booklist" > 7 <book> 8 <title> e-Business and e-Commerce How to Program </title> 9 <title> C# How to Program </title> 10 </book> 11 <book> 12 <title> Python How to Program </title> 13 </book> 14 </deitel:books> Extra title element in book invalidate the document
55. bookxdrfail.xml Program output 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.22: bookxdrfail.xml --> 4 <!-- XML file that does not conform to Schema book.xdr --> 5 6 <books xmlns = "x-schema:book.xdr" > 7 <book> 8 <title> XML How to Program </title> 9 </book> 10 11 <book> 12 <title> Java How to Program, 4/e </title> 13 </book> 14 15 <book> 16 <title> Visual Basic .NET How to Program </title> 17 </book> 18 19 <book> 20 <title> C++ How to Program, 3/e </title> 21 <title> Python How to Program </title> 22 </book> 23 24 <book> 25 <title> C# How to Program </title> 26 </book> 27 </books> Too many titles causes document to be invalid
56.
57. Sorting.xml 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.23: sorting.xml --> 4 <!-- XML document containing book information --> 5 6 <?xml:stylesheet type = "text/xsl" href = "sorting.xsl" ?> 7 8 <book isbn = "999-99999-9-X" > 9 <title> Deitel's XML Primer </title> 10 11 <author> 12 <firstName> Paul </firstName> 13 <lastName> Deitel </lastName> 14 </author> 15 16 <chapters> 17 <frontMatter> 18 <preface pages = "2" /> 19 <contents pages = "5" /> 20 <illustrations pages = "4" /> 21 </frontMatter> 22 23 <chapter number = "3" pages = "44" > 24 Advanced XML </chapter> 25 26 <chapter number = "2" pages = "35" > 27 Intermediate XML </chapter> 28 29 <appendix number = "B" pages = "26" > 30 Parsers and Tools </appendix> 31 Processing instruction Application-specific information embedded into XML document Processing instruction value Processing instruction target Specify name and location of style sheet to apply
58. Sorting.xml 32 <appendix number = "A" pages = "7" > 33 Entities </appendix> 34 35 <chapter number = "1" pages = "28" > 36 XML Fundamentals </chapter> 37 </chapters> 38 39 <media type = "CD" /> 40 </book>
59. Sorting.xsl 1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 18.24: sorting.xsl --> 4 <!-- Transformation of book information into XHTML --> 5 6 <xsl:stylesheet version = "1.0" 7 xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" > 8 9 <!-- write XML declaration and DOCTYPE DTD information --> 10 <xsl:output method = "xml" omit-xml-declaration = "no" 11 doctype-system = 12 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 13 doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN" /> 14 15 <!-- match document root --> 16 <xsl:template match = "/" > 17 <html xmlns = "http://www.w3.org/1999/xhtml" > 18 <xsl:apply-templates/> 19 </html> 20 </xsl:template> 21 22 <!-- match book --> 23 <xsl:template match = "book" > 24 <head> 25 <title> ISBN <xsl:value-of select = "@isbn" /> - 26 <xsl:value-of select = "title" /></title> 27 </head> 28 29 <body> 30 <h1 style = "color: blue" > 31 <xsl:value-of select = "title" /></h1> 32 XSL document is an XML document Root element Write document type declaration to the result tree Calls for all template that match children of the document root to be applied Specifies a template that match es element book Title for XHTML document
60. Sorting.xsl 33 <h2 style = "color: blue" > by <xsl:value-of 34 select = "author/lastName" /> , 35 <xsl:value-of select = "author/firstName" /></h2> 36 37 <table style = 38 "border-style: groove; background-color: wheat" > 39 40 <xsl:for-each select = "chapters/frontMatter/*" > 41 <tr> 42 <td style = "text-align: right" > 43 <xsl:value-of select = "name()" /> 44 </td> 45 46 <td> 47 ( <xsl:value-of select = "@pages" /> pages ) 48 </td> 49 </tr> 50 </xsl:for-each> 51 52 <xsl:for-each select = "chapters/chapter" > 53 <xsl:sort select = "@number" data-type = "number" 54 order = "ascending" /> 55 <tr> 56 <td style = "text-align: right" > 57 Chapter <xsl:value-of select = "@number" /> 58 </td> 59 60 <td> 61 ( <xsl:value-of select = "@pages" /> pages ) 62 </td> 63 </tr> 64 </xsl:for-each> 65 Select each element that is a child of element frontMatter Node-set function name called to retrieve current node’s element name Sort chapters by number in ascending order Attribute select selects value of context node chapter ’s attribute number Specify numeric search
63. TransformTest.cs 1 // Fig. 18.25: TransformTest.cs 2 // Applying a style sheet to an XML document. 3 4 using System; 5 using System.Windows.Forms; 6 using System.Xml; 7 using System.Xml.XPath; // contains XPath classes 8 using System.Xml.Xsl; // contains style sheet classes 9 using System.IO; // contains stream classes 10 11 // transforms XML document to XHTML 12 public class TransformTest : System.Windows.Forms.Form 13 { 14 private System.Windows.Forms.TextBox consoleTextBox; 15 private System.Windows.Forms.Button transformButton; 16 private System.ComponentModel.Container components = null ; 17 18 private XmlDocument document; // Xml document root 19 private XPathNavigator navigator; // navigate document 20 private XslTransform transformer; // transform document 21 private StringWriter output; // display document 22 23 public TransformTest() 24 { 25 InitializeComponent(); 26 27 // load XML data 28 document = new XmlDocument(); 29 document.Load( "....sports.xml" ); 30 31 // create navigator 32 navigator = document.CreateNavigator(); 33 Necessary for transforming XML data to another format XML document parsed and loaded into memory Create an XpathNavigator object to navigate document through transformation
64. TransformTest.cs 34 // load style sheet 35 transformer = new XslTransform(); 36 transformer.Load( "....sports.xsl" ); 37 } // end constructor 38 39 // Windows Form Designer generated code 40 41 [STAThread] 42 static void Main() 43 { 44 Application.Run( new TransformTest() ); 45 } // end Main 46 47 // transformButton click event 48 private void transformButton_Click( object sender, 49 System.EventArgs e ) 50 { 51 // transform XML data 52 output = new StringWriter(); 53 transformer.Transform( navigator, null , output ); 54 55 // display transformation in text box 56 consoleTextBox.Text = output.ToString(); 57 58 // write transformation result to disk 59 FileStream stream = new FileStream( "....sports.html" , 60 FileMode.Create ); 61 StreamWriter writer = new StreamWriter( stream ); 62 writer.Write( output.ToString() ); 63 64 // close streams 65 writer.Close(); 66 output.Close(); 67 } // end transformButton_Click 68 } // end TransformTest Style sheet sports.xsl to be used on sports.xml To apply style sheet Result of transformation stored in StringWriter object referenced by output Method Transform of class XslTransform An XPathNavigator created from sports.xml’s XmlDocument An instance of class XsltArgumentList Write output to a file