XML Validator

Why XML Validator

We have already discussed that an XML should have code written in such a way that each tag is closed at correct position. Sometimes, we forget to close a tag and if the length of the code is too long, then it becomes tedious to find out the missing tag. In such cases, we can use a XML validator.

Example

Suppose you have a big piece of code as shown below:

<mvc:View controllerName="RuDeLabs.RuDeLabs.controller.Main" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" displayBlock="true"
    xmlns="sap.m" xmlns:upload="sap.m.upload">
    <Shell id="shell">
        <App id="app">
            <pages>
                <Page id="page" title="{i18n>title}" titleAlignment="Center">
                    <customHeader>
                        <Bar>
                            <contentMiddle>
                                <Title text="{i18n>title}"/>
                            </contentMiddle>
                            <contentRight>
                                <Button text="Reset" press="onReset"/>
                            </contentRight>
                        </Bar>
                    </customHeader>
                    <VBox height="100%" alignItems="Center">
                        <HBox height="100%">
                            <VBox>
                                <Label design="Bold" text="Update Existing Document" required="true"/>
                                <Switch id="idSwitch" state="false" customTextOn="Yes" customTextOff="No"/>
                                <Label design="Bold" text="{i18n>collection}" required="true"/>
                                <Input width="300px" id="idCollection" required="true"/>
                                <Label design="Bold" text="{i18n>docs}" required="true"/>
                                <Select id="idType" selectedKey="text" width="100%" change="onSelectType">
                                    <core:Item key="text" text="Text"/>
                                    <core:Item key="images" text="Images"/>
                                    <core:Item key="stickers" text="Stickers"/>
                                </Select>
                                <VBox id="idVBoxLangu">
                                    <Label design="Bold" text="{i18n>langu}" required="true"/>
                                    <Select id="idLangu" selectedKey="English" width="100%" change="onSelectLangu">
                                        <core:Item key="Arabic" text="Arabic"/>
                                        <core:Item key="Bengali" text="Bengali"/>
                                        <core:Item key="English" text="English"/>
                                        <core:Item key="French" text="French"/>
                                        <core:Item key="German" text="German"/>
                                        <core:Item key="Hebrew" text="Hebrew"/>
                                        <core:Item key="Hindi" text="Hindi"/>
                                        <core:Item key="Italian" text="Italian"/>
                                        <core:Item key="Punjabi" text="Punjabi"/>
                                        <core:Item key="Russian" text="Russian"/>
                                        <core:Item key="Spanish" text="Spanish"/>
                                    </Select>
                                </VBox>
                                <Label id="idContent" design="Bold" text="Your Content" required="true" design="Bold"/>
                                <TextArea id="idData" width="300px" placeholder="Enter your content, verify spaces and press verify button below."/>
                                <Button text="Verify" width="100%" press="onInputChange"/>
                                <UploadCollection id="idMultiUploader" visible="false" maximumFilenameLength="55" maximumFileSize="10" multiple="true"
                                    sameFilenameAllowed="false" instantUpload="false" change="onChangeUpload" fileDeleted="onFileDeleted" fileType="png"
                                    filenameLengthExceed="onFilenameLengthExceed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch"
                                    uploadComplete="onUploadComplete" beforeUploadStarts="onBeforeUploadStarts"/>
                                <TextArea id="idTextArea" editable="false" growing="false" width="300px" visible="false"/>
                            </VBox>
                        </HBox>
                    </VBox>
                    <footer>
                        <OverflowToolbar>
                            <Text text="Ver 1.3"/>
                            <ToolbarSpacer/>
                            <Button text="Push Data" press="onAddDateToCollection"/>
                        </OverflowToolbar>
                    </footer>
                </Page>
            </pages>
        </App>
    </Shell>
</mvc:View>

Now the above XML snippet is not working and you are confused, what is wrong with the above code. In cases like this, where you are not sure and the error is not visible, we check the above XML data with a validator tool.
After running the same, we get given output.

XML Validator

Based upon above findings, we can easily fix our code.

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.