XHTML Interview Questions and Answers for 7 years experience
-
What is XHTML and how does it differ from HTML?
- Answer: XHTML (Extensible HyperText Markup Language) is a reformulation of HTML as an XML application. Key differences include stricter syntax requirements (e.g., all tags must be closed, attributes must be enclosed in quotes, and lowercase tag names are recommended), and its adherence to XML's well-formedness rules. HTML is more forgiving of syntax errors.
-
Explain the concept of well-formed XML and how it applies to XHTML.
- Answer: A well-formed XML document follows specific structural rules. This includes a single root element, properly nested tags, closed tags, and correct attribute quoting. XHTML, being an XML application, must be well-formed. This stricter structure ensures greater consistency and improves interoperability.
-
What are the different XHTML doctypes? Explain their significance.
- Answer: XHTML doctypes declare the version of XHTML being used and influence how browsers render the page. Examples include XHTML 1.0 Strict, Transitional, and Frameset. Strict is the most conforming, omitting presentational elements. Transitional allows some presentational elements for backward compatibility. Frameset supports frames.
-
Explain the importance of using a DOCTYPE declaration in XHTML.
- Answer: The DOCTYPE declaration tells the browser which version of XHTML the document adheres to. This allows the browser to render the page correctly according to the specified standards. Omitting it can lead to quirks mode, where the browser's rendering behavior may be inconsistent.
-
Describe the role of namespaces in XHTML.
- Answer: Namespaces in XML (and thus XHTML) provide a mechanism to avoid naming conflicts when combining elements from different XML vocabularies. They help disambiguate elements with the same name but different meanings. This is particularly useful when incorporating SVG or MathML into an XHTML page.
-
How do you handle user input in XHTML to prevent XSS (Cross-Site Scripting) vulnerabilities?
- Answer: Always sanitize user input before displaying it on the page. Methods include encoding special characters (e.g., using HTML entities like < for <) or using parameterized queries (for database interactions). Never trust user input directly.
-
What are the advantages and disadvantages of using XHTML compared to HTML5?
- Answer: Advantages of XHTML: Stricter syntax leads to more robust and valid code. Better compatibility with XML-based technologies. Disadvantages: More verbose syntax compared to HTML5. HTML5 offers more semantic elements and features, making it easier to create accessible and well-structured web pages. Browser support for XHTML is declining.
-
Explain how to create a valid XHTML document.
- Answer: To create a valid XHTML document: 1) Start with a proper DOCTYPE declaration. 2) Ensure all tags are properly nested and closed. 3) Use lowercase for tag names. 4) Enclose attribute values in quotes. 5) Use a validating XML parser to check for errors.
-
How would you embed CSS into an XHTML document? Describe different methods.
- Answer: Methods include inline styles (within the element's tag), embedded styles (within the `