# XML - Managing Data Exchange/NetBeans

NetBeans

# Using an XML Editor: NetBeans : Single - Entity
## NetBeans IDE 5.0 instruction

* Launch NetBeans
* Make yourself familiar with the IDE by opening Help > Help Contents and reading the material in Getting Started
* Create a new project by File > New Project.. (Ctrl+Shift+N)
* Under "Choose a Project:" select under Categories: General
* Select under Projects: Java Application
* Press Next
* Name the project name appropriately (e.g., xml1)
* Check "Set as Main Project" and un-check "Create Main Class"
* Save to the appropriate location
* Press Finish
* Right click just created project (e.g., xml1) from Projects window
* Create a new file by New > File/Folder > XML > XML document
* Name the file (e.g., city)
* Press Next
* Select "Well-formed Document"
* Press Finish
* You should see the following skeleton XML file: <?xml version="1.0" encoding="UTF-8"?> <!-- Document : city.xml Created on : December 26, 2005, 11:18 AM Author : rtw Description: Purpose of the document follows. --> <root> </root>
* The goal is to create a simple markup file, rather than an XML file, so replace the section delimited by <root> and </root> in the skeleton XML file with the lines in Table 1. After the change, the file should look like: <?xml version="1.0" encoding="UTF-8"?> <!-- Document : city.xml Created on : December 26, 2005, 11:18 AM Author : rtw Description: Purpose of the document follows. --> <city> <cityname>Athens</cityname> <state>GA</state> <description> Home of the University of Georgia</description> <population>100,000</population> <location>Located about 60 miles Northeast of Atlanta</location> <latitude>33 57' 39"N</latitude> <longitude>83 22' 42" W</longitude> </city>
* Check the markup file is well-formed by clicking on the single green downward point triangle on the XML tool bar above the document listing. It should pass the check. Alternatively, use Alt+F9 (Windows) or Ctrl+F9 (Mac).
* Delete the tag </city> and check the file again. This time you should get an error indicating that an end tag is missing. "XML document structures must start and end within the same entity." followed by the line number (where the error occurs) in brackets should appear in blue and underlined.
   NetBeans is an open source IDE that includes an XML editor.

### XML document:

* Go to File -> New File -> XML -> XML Document.
* Save your file as ‘city’
* Select XML Schema-Constrained Document as the document type.
* Next, specify your schema location (Go to Browse, then select the schema just created) and root element name (tourGuide).
* Copy and paste the above code into the NetBeans editor and save.
* Check the XML document to make sure it is well-formed (ALT-F9).
To validate an XML document:
* Right-click the document's node and choose Validate XML.
If the XML file, city.xml, conforms to the XML schema provided, city.xsd, your Output Window should look like the following:
Open this file, city.xml, in NetBeans.
* Summary: Being a file which contains XML code and syntax, the XML document is an entity of neatly organized elements and subelements.

#### Netbeans Tips

The prefix "xsi" for attribute "xsi:noNamespaceSchemaLocation" associated with an element type "Listing" is not bound.
cvc-elt.1: Cannot find the declaration of element 'Listing'.
cvc-complex-type.2.4.a: Invalid content was found starting with element 'MuseumName'. One of '{"":Museum}' is expected. [5]
The element type "MuseumName" must be terminated by the matching end-tag "</MuseumName>".

### XML Schema

Any XML document, including XML schema and XML stylesheet documents, can be checked to make sure they are “well-formed”. An XML document is said to be well-formed if it adheres to the XML syntax rules, as outlined in the Chapter 1, such as there must be exactly one root element, every start tag must have an end tag. The well-formedness of an XML documents can be checked using an XML editor software, in this case, the NetBeans. If any errors are detected, they are listed along with the line number in the Output window. This location is not necessarily the line where the error occurred. By double-clicking on any error message, you can go to the line in the XML document where the error was detected.
Use NetBeans to create a new project:
* Go to File -> New Project
Use NetBeans to create the above XML schema:
* Go to File -> New File -> XML -> XML Schema.
* Save your file as ‘city’ (this gives the file an extension of .xsd).
* Copy and Paste the above schema into city.xsd and save
To check an XML document to see if it is well-formed:
* Right-click the document's node (under files, city.xsd) and choose Check XML schema or press Alt-F9.
If the XML schema, city.xsd, is well-formed, your Output Window should look like this:
* Summary: The XML schema shows the structure and elements of an XML document.

#### Netbeans Tips

Element type "xsd:element" must be followed by either attribute specifications, ">" or "/>".
The value of attribute "name" associated with an element type "xsd:complexType" must not contain the '<' character.
src-resolve.4.2: Error resolving component 'xsd:strin'...
The element type "xsd:sequence" must be terminated by the matching end-tag "</xsd:sequence>".

### XML Stylesheet

Use NetBeans to create the above XML stylesheet:
* Go to File -> New File -> XML -> XSL Stylesheet
* Save your file as ‘city’
* Copy and paste the above code into the NetBeans editor and save.
* Check the stylesheet to make sure it is well-formed (ALT-F9).
Note: The city example files (city.xsd, city.xml and city.xsl) can be created using a text editor, and the results are displayed correctly in a compatible web browser such as Mozilla 1.6. You will need to store all of the files in the same directory and insert the following line after line 1 of city.xml: <?xml-stylesheet href="city.xsl" type="text/xsl"?>
This associates the XSL Stylesheet with the XML file containing the city data. Also, If you are using Netbeans, be sure to take off the xmlns line in the beginning which looks like xmlns='http://xml.netbeans.org/examples/targetNS', otherwise it will not display all data.

#### Netbeans Tips

The element type "xsl:text" must be terminated by the matching end-tag "</xsl:text>".
The element type "xsl:for-each" must be terminated by the matching end-tag "</xsl:for-each>".