pp108 : XMLUtil

XMLUtil


Helps in handling and displaying the XML documents to the user.

Syntax

HTML

<div cordysType="wcp.library.util.XMLUtil" id="utilID">
    <div>
    ...
    </div>
</div>

where id refers to the unique identifier of the XMLUtil component.

To dynamically add and initialize this component, you can use the initializeHTMLElements or addTypemethods of the Application object.
The following property, methods, and events are exposed by this library for handling the XML document.

Table 1. List of Properties

Property

Description

Region

Sets the region property, which is a string that defines the name of the region in which the xmlPopup and xmlEdit dialog boxes are to be opened.

Table 2. List of Methods

Method

Description

xmlPopup (XML, modeless, title)

Displays a dialog box with the XML content. The XML parameter contains the XML document to be displayed. The modeless parameter is a Boolean parameter. If it is true, a modeless dialog box is displayed; else, a modal dialog box is displayed. The title parameter is used for displaying the title of the window that is opened. The XML document shown in this dialog box is not editable.

xmlEdit(XML,modeless, title)

Displays a dialog box with the XML content. The XML parameter contains the XML document to be displayed. The modeless parameter is a Boolean parameter. If it is true, a modeless dialog box is displayed; else, a modal dialog box is displayed. The title parameter is used for displaying the title of the window that is opened. The XML document shown in this dialog box is editable.

xml2html(XML,HTML)

Formats and sets the XML document in the HTML object as its innerHTML. The XML parameter takes the XML document to displayed and HTML parameter is the ID of the HTML element whose innerHTML property will be set to the formatted XML. In case the HTML object is not mentioned, the function returns the formatted XML.

xml2htmlstring(XML,HTML)

Formats the XML document and sets it as the innerText of the specific HTML object. In case the HTML object is not mentioned, it returns the formatted XML.

xml2string(XML, HTML)

Formats and sets the XML as the innerText of the specific HTML object and in case the HTML object is not mentioned, it returns the formatted XML as a string.

xml2nicestring(XML, level, htmlobject)

Formats and sets the XML as the innerText of the specific HTML object and in case the HTML object is not mentioned, it returns the formatted XML as a string with all the new lines and indents. The level parameter determines the number of white spaces to be kept before the formatted XML document.

xml2nicestringPopup(xml, modeless, title) Formats the XML and shows the formatted XML in a separate application. If modeless is true, the application will be opened in the same window; otherwise, the model window dialog will be opened.
checkAndReportError(xmlSrc) Verifies if any parse error is present in the XML and if any, it reports the error.
Table 3. List of Events

Event

Description

oneditdone

Fired when the editing window is closed after modifying data using the xmlEdit() method. You can use the eventObject.editedXML property to retrieve the data modified.

Example

The following example shows the usage of this component:

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>Demo of XMLUtil</title>
    <script type="text/javascript" src="/cordys/wcp/application.js" ></script>   
<script type="text/javascript" >
        function showXMLPopup()
        {
           var model = document.getElementById("model").checked;
           var x= XMLUtil.xmlPopup(menuData.XMLDocument.documentElement, model, "Formatted XML");
        }
        
        function showXMLEdit()
        {
           var model = document.getElementById("model").checked;
           var x= XMLUtil.xmlEdit(menuData.XMLDocument.documentElement, model, "Formatted XML");
           XMLUtil.addListener("oneditdone", onEditDoneListener);
        }
        
        function showXML2nicestringPopup()
        {
           var model = document.getElementById("model").checked;
           var x= XMLUtil.xml2nicestringPopup(menuData.XMLDocument.documentElement, model, "Formatted XML");

        }
              
       function onEditDoneListener(eventObject)
       {
       	   if(eventObject.editedXML)
		   {
				application.notify("modifiedXML-- \n"+cordys.getXML(eventObject.editedXML));
		   }
	   }
 
</script>
<script type="cordys/xml" id="menuData" >
    <menu>
        <MainNode>
            <caption>Demo Using Menu Node</caption>
            <description>Demo Using Menu Node</description>
            <Continents>
                <caption>Continents</caption>
                <description>Continents</description>
                <Continent>
                    <caption>Asia</caption>
                    <description>mmm</description>
                    <Country>
                        <caption>India</caption>
                        <description>India is my Country</description>
                    </Country>
                    <Country>
                        <caption>Japan</caption>
                        <description>Japan popular for electronic trends</description>
                    </Country>
                </Continent>
                <Continent>
                    <caption>Europe</caption>
                    <description>Europe</description>
                    <Country>
                       <caption>The NetherLands</caption>
                        <description>The NetherLands</description>
                    </Country>
                    <Country>
                        <caption>UK</caption>
                        <description>UK</description>
                    </Country>
                </Continent>
            </Continents>
            <Oceans>
                <caption>Oceans</caption>
                <description>Oceans</description>
                <Ocean>
                    <caption>The Great Ocean</caption>
                    <description>Atlantic</description>
                    <id>GeneralInformation</id>
                </Ocean>
            </Oceans>
        </MainNode>      
    </menu>
</script>
</head>
<body bottommargin=20 leftmargin=20 rightmargin=20 topmargin=20>
<div cordysType="wcp.library.util.XMLUtil" id="XMLUtil" automatic="false" async="false" style="display:none"></div>
    <h3>Demo of XMLUtil</h3>   
    <div><input type="checkbox" id="model" style="width:50px;top:50px" name="Model  " title="Model">Modeless </input>
        <br />
        <br />
   <button class="medium" onclick="showXMLEdit()" style="width: 118px" >xmlEdit</button>
   <button class="medium" onclick="showXMLPopup()" id="BUTTON1" style="width: 124px" >XML Popup</button>
   <button class="medium" onclick="showXML2nicestringPopup()" style="width: 137px" >xml2nicestringPopup</button></div>  
   
</body>
</html>