XML

<< Click to Display Table of Contents >>

Navigation:  Concepts >

XML

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human- and machine-readable. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications which are all free open standards.

Why is CAD XML API based on XML?

XML:

is used straightforwardly over the Internet;

supports a wide variety of applications;

it is easy to write programs that process XML documents.

XML document:

is ordinary text files (UTF8, UTF16, ...);

is properly nested brackets/tags describing a tree structure;

allows applications from different vendors to exchange data;

is standardized and widely accepted;

is human-legible and reasonably clear;

is easy to create.

That is why XML has been chosen as the basis for CAD XML API.

All XML API commands are text documents created according to the rules of the XML Specification produced by the W3C.

To understand XML API correctly it is very important to know two terms on which the work of XML API is based:

1. XML API document

2.  XML API instruction

An XML API instruction is a part of an XML API document. The XML API document should contain at least one instruction. However, the number of instructions in one XML API document can be more than one. The number of instructions in an XML API document is limited only by the size of the computer RAM that is necessary for correct processing of all the instructions.

The source code for the XML API document should contain:

XML document declaration

start tag of the root node

XML API Command(s)

end tag of the root node

Tags

start tag < >

end tag </>

empty-element tag </>

Comments

Comments may appear anywhere in the XML API document outside of other markups. Comments cannot appear before the XML declaration. Comments start with "<!--" and end with "-->".

Example:

<!-- XML document declaration -->
<?xml version="2.0" encoding="UTF-8"?>
<!-- start-tag of the root node -->
<cadsofttools version="2">    
  <!-- XML command GET -->
  <get/>
<!-- end-tag of the root node -->
</cadsofttools>

Note: XML API supports Unicode and we strongly recommend to use Unicode encoding XML API documents to prevent possible loss of data.

Commands

An XML API command is an element of the XML document that either begins with a start tag and ends with a matching end tag or consists only of an empty element tag.

The characters between the start and end tags define the XML API command.  

The XML API command may have a list of input parameters, if any, the parameters are defined with the help of attributes consisting of a name/value pair that exists between the start tag and the end tag of the XML API command.

Note: Letter case is ignored in XML API commands, that means that you can write both <get>  or <Get> with the same result.

Example:

The GET instruction may have no parameters:

<!-- XML document declaration -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- start-tag of the root node -->
<cadsofttools version="2.0">    
  <!-- XML command GET -->
  <get> </get>
<!-- end-tag of the root node -->
</cadsofttools>

The GET instruction can also be written with an empty element tag:

<!-- XML document declaration -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- start-tag of the root node -->
<cadsofttools version="2.0">    
  <!-- XML command GET with empty-element tag-->
  <get/>
<!-- end-tag of the root node -->
</cadsofttools>

The APPLY instruction has a list of parameters:

<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2.0">
 <Select Handle="@1"/>
<!-- XML API command APPLY parameters are lineweight="7" point1="50,10,0" Color="0;33;" -->  
 <apply lineweight="7" point1="50,10,0" Color="0;33;"/>
 <UnSelect Handle="@1"/>
 <!-- Zoom rect of tne selected entities to the screen -->
 <ShowSelectedEntities/>
</cadsofttools>

How to Create and Process XML

Go to CADEditorX