# XML - Managing Data Exchange/Using an XML Editor

NetBeans

# Using an XML Editor: NetBeans : Single - Entity

Return to the Single Entity Chapter => [[../A single entity/]

### 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:
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>".