XML - Managing Data Exchange/Using an XML Editor

NetBeans

Using an XML Editor: NetBeans : Single - Entity

edit

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

XML document:

edit
  1. Go to File -> New File -> XML -> XML Document.
  2. Save your file as ‘city’
  3. Select XML Schema-Constrained Document as the document type.
  4. Next, specify your schema location (Go to Browse, then select the schema just created) and root element name (tourGuide).
  5. Copy and paste the above code into the NetBeans editor and save.
  6. Check the XML document to make sure it is well-formed (ALT-F9).

To validate an XML document:

  1. 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

edit

The prefix "xsi" for attribute "xsi:noNamespaceSchemaLocation" associated with an element type "Listing" is not bound.

     -Caused because line
      "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" is 
      missing from the top of the document.

cvc-elt.1: Cannot find the declaration of element 'Listing'.

     -Caused due to lack of extension(.xsd) at the end of the schema
      name.

cvc-complex-type.2.4.a: Invalid content was found starting with element 'MuseumName'. One of '{"":Museum}' is expected. [5]

     -Caused due to lack of naming at the beginning and end of the
      variable naming section.

The element type "MuseumName" must be terminated by the matching end-tag "</MuseumName>".

     -Could be caused by a missing "/" in the end tag of one of the
      variables

XML Schema

edit

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:

  1. Go to File -> New Project

Use NetBeans to create the above XML schema:

  1. Go to File -> New File -> XML -> XML Schema.
  2. Save your file as ‘city’ (this gives the file an extension of .xsd).
  3. Copy and Paste the above schema into city.xsd and save

To check an XML document to see if it is well-formed:

  1. 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

edit

Element type "xsd:element" must be followed by either attribute specifications, ">" or "/>".

     -Caused by lack of ">" or "/>" symbol at the end of either the 
      specified line or the line there after.

The value of attribute "name" associated with an element type "xsd:complexType" must not contain the '<' character.

     -Often caused by lack of closing quotation around the variable 
      name on either the specified line or the line there after.

src-resolve.4.2: Error resolving component 'xsd:strin'...

     -Caused by invalid "type", most likely misspelled.  Can be for 
      any "type", not just "string."

The element type "xsd:sequence" must be terminated by the matching end-tag "</xsd:sequence>".

     -Caused because </xsd:sequence> is not found in order to close 
      the statement.  
     -Also caused because the closing statements are out of order as
      they at the beginning of the Schema.

XML Stylesheet

edit

Use NetBeans to create the above XML stylesheet:

  1. Go to File -> New File -> XML -> XSL Stylesheet
  2. Save your file as ‘city’
  3. Copy and paste the above code into the NetBeans editor and save.
  4. 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

edit

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

     -Caused by either lack of end-tag or misspelling of the end-
      tag.

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

     -Caused due to either lack of end-tag for the specified tag or 
      end-tags placed in the wrong order.