IT 310 Web Dev

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which characteristic makes XML data storage software and hardware independent?

  • XML's use of predefined tags.
  • XML requires conversion into binary format for storage.
  • XML stores data in plain text format. (correct)
  • XML's ability to work only on specific operating systems.

How does XML facilitate system upgrades and expansions?

  • By making it easier to expand or upgrade to new systems without losing data. (correct)
  • By requiring data conversion before upgrading.
  • By exclusively supporting older operating systems.
  • By preventing new applications from accessing the stored data.

What is the primary focus when using XML?

  • Determining what the data is. (correct)
  • Defining how the data should look.
  • Using predefined HTML tags.
  • Focusing on visual presentation.

In XML, who is responsible for defining the tags?

<p>The author of the XML document defines both tags and document structure. (B)</p> Signup and view all the answers

What aspect of data is NOT carried by XML?

<p>Instructions on how to display the data. (A)</p> Signup and view all the answers

Which of the following is a mandatory syntax rule in XML?

<p>All XML elements must have a closing tag. (C)</p> Signup and view all the answers

What is the correct way to nest elements in XML?

<p><code>&lt;b&gt;&lt;i&gt;text&lt;/i&gt;&lt;/b&gt;</code> (B)</p> Signup and view all the answers

How should attribute values be represented in XML?

<p>Using single or double quotes. (A)</p> Signup and view all the answers

Why are entity references necessary in XML?

<p>To represent characters with special meaning. (C)</p> Signup and view all the answers

Which of the following is NOT a valid XML element name?

<p><code>&lt;xmlData&gt;</code> (B)</p> Signup and view all the answers

What is the purpose of XML metadata?

<p>To provide additional information about the data within the XML document. (D)</p> Signup and view all the answers

When might naming conflicts occur in XML, and how can they be resolved?

<p>Conflicts can occur when elements have the same name but different meanings; they are resolved by using namespaces. (D)</p> Signup and view all the answers

What is the role of the XMLHttpRequest object in web development?

<p>To request data from a web server. (A)</p> Signup and view all the answers

What functionality does the XMLHttpRequest object provide to a developer?

<p>Ability to update a web page without reloading the page. (D)</p> Signup and view all the answers

Which of the following is a key component of using the XMLHttpRequest object in JavaScript?

<p>Specifying the action to take when the document is ready. (C)</p> Signup and view all the answers

What does the XML DOM (Document Object Model) define?

<p>A standard for accessing and manipulating documents. (D)</p> Signup and view all the answers

Why is it necessary to load an XML document into an XML DOM object before it can be accessed?

<p>To provide a structured way to access and manipulate XML data. (B)</p> Signup and view all the answers

What is the primary function of XSLT?

<p>To transform an XML document into HTML or other formats. (C)</p> Signup and view all the answers

What is XPath used for in the context of XML and XSLT?

<p>To find information in an XML document. (B)</p> Signup and view all the answers

AJAX is a combination of which technologies?

<p>A browser built-in XMLHttpRequest object, JavaScript, and HTML DOM. (D)</p> Signup and view all the answers

What is the primary benefit of using AJAX in web development?

<p>It enables web pages to be updated asynchronously, without full page reloads. (A)</p> Signup and view all the answers

In an AJAX workflow, what is the sequence of steps after a user action triggers an event?

<p>XMLHttpRequest object is created -&gt; The XMLHttpRequest object sends a request to a web server. (B)</p> Signup and view all the answers

What is the role of the onreadystatechange property in AJAX?

<p>It defines a function to be executed when the readyState property changes. (A)</p> Signup and view all the answers

Which of the readyState values indicates that the request is finished and the response is ready?

<p>4 (D)</p> Signup and view all the answers

When should POST requests be used instead of GET requests in AJAX?

<p>When updating a file or database on the server. (A)</p> Signup and view all the answers

Why is setting the async parameter to true recommended when using the open() method of an XMLHttpRequest object?

<p>It allows other scripts to execute while waiting for the server response. (D)</p> Signup and view all the answers

What is the primary difference between synchronous and asynchronous requests?

<p>Synchronous requests do not require a callback function. (C)</p> Signup and view all the answers

What is the purpose of JSON?

<p>To format data for easy exchange between a server and a web application. (B)</p> Signup and view all the answers

Why might JSON be preferred over XML in some situations?

<p>JSON's syntax is simpler than XML, leading to smaller file sizes and easier parsing in JavaScript. (D)</p> Signup and view all the answers

How can you convert a JSON string into a JavaScript object?

<p>Using the <code>JSON.parse()</code> method. (C)</p> Signup and view all the answers

Which method is used to convert a JavaScript object into a JSON string?

<p><code>JSON.stringify()</code> (B)</p> Signup and view all the answers

Why is using eval() generally discouraged when parsing JSON data?

<p><code>eval()</code> does not filter out potentially dangerous code. (A)</p> Signup and view all the answers

If you have a JSON object data with a property window that has a property title, how do you access the title in JavaScript?

<p><code>data.window.title</code> (A)</p> Signup and view all the answers

Which of the following snippets correctly retrieves the first element's 'title' value from a JSON structure parsed into a JavaScript variable named data?

<p><code>data.books[0].title</code> (A)</p> Signup and view all the answers

What HTTP method is typically used for retrieving data from a server using AJAX?

<p>GET (C)</p> Signup and view all the answers

What is the purpose of the setRequestHeader() method in the XMLHttpRequest object?

<p>To set a custom header for the request. (A)</p> Signup and view all the answers

Flashcards

What is XML?

XML stores data in plain text format for software/hardware independence.

XML vs. HTML?

XML carries data, HTML displays it.

XML tags?

XML tags created by the author.

XML Presentation?

XML does not carry any information about how to be displayed.

Signup and view all the flashcards

Root element?

All XML documents must have one root element.

Signup and view all the flashcards

XML Prolog

Specifies the XML version and character encoding

Signup and view all the flashcards

XML Closing Tags

XML elements must have a closing tag

Signup and view all the flashcards

XML Nesting

In XML, all elements MUST be correctly nested.

Signup and view all the flashcards

XML Attributes?

XML attribute values quoted.

Signup and view all the flashcards

Entity References

special characters replaced by code.

Signup and view all the flashcards

XML Comment Syntax

Signup and view all the flashcards

XPath

a syntax for defining parts of an XML document

Signup and view all the flashcards

XPath and Paths

Use path expressions.

Signup and view all the flashcards

AJAX Full Name

Asynchronous JavaScript and XML

Signup and view all the flashcards

AJAX Is..?

Not a programming language but a combination

Signup and view all the flashcards

AJAX Communication

Browser -> Server -> Browser without full page reload

Signup and view all the flashcards

XMLHttpRequest

Built-in object for requesting data from a server.

Signup and view all the flashcards

AJAX Request Methods

Use open() and send() methods.

Signup and view all the flashcards

AJAX Open() Method

the type of request: GET or POST

Signup and view all the flashcards

GET vs. POST?

Simpler and faster but not for secure input.

Signup and view all the flashcards

AJAX Asynchronous?

The third parameter should be set to true

Signup and view all the flashcards

onreadystatechange

Defines a function to be executed when the request receives an answer.

Signup and view all the flashcards

Verify AJAX Response?

readyState and status are the keys.

Signup and view all the flashcards

JSON?

Data format as set of JavaScript objects.

Signup and view all the flashcards

Using JSON

Use Ajax to fetch data then JSON.parse.

Signup and view all the flashcards

Study Notes

Web Systems and Technologies 2

  • The course offers understanding of extensible markup language and document object model.
  • The course teaches how to achieve a logical structure of data and how to access and manipulate it.
  • XML HTTP request objects are used to communicate with servers and send information in various formats.
  • Students learn to use libraries like jQuery and jQuery UI for manipulating web page objects, event handling, and animation.

What is XML?

  • XML stores data in plain text.
  • XML offers software and hardware independence for storing, transporting, and sharing data.
  • XML makes it easier to expand or upgrade to new systems, applications, or browsers without losing data.
  • With XML, data is available to all reading machines such as people, computers, voice machines, and news feeds.
  • XML applications function as expected even if data is added or removed.
  • XML consists of sender and receiver information, heading, and a message body.

XML vs HTML

  • XML carries data with a focus on what the data is.
  • HTML displays data with focus on how data looks.
  • XML tags are not predefined, unlike HTML tags.
  • There are no predefined tags in XML, the tags used are not pre defined in any XML standard.
  • The author of the XML document invents the tags.
  • HTML works with predefined tags such as p, h1 and table.
  • With XML, the author defines both the tags and the document structure.
  • XML does not carry any display information and seperates data from presentation.

XML Structure

  • XML has tree structure
  • Root element can contain child and subchild elements

XML Syntax Rules

  • XML documents must have a root element.
  • The XML prolog is optional.
  • All XML elements require a closing tag.
  • XML tags are case sensitive.
  • XML elements must be properly nested.
  • XML attribute values must always be quoted.

Entity References

  • Certain characters have a special meaning in XML.
  • Placing characters such as "<" inside an XML element generates an error.
  • Replace the "<" character with an entity reference to avoid errors.
  • The 5 pre-defined entity references in XML are:
    • &lt; for less than (<)
    • &gt; for greater than (>)
    • &amp; for ampersand (&)
    • &apos; for apostrophe (')
    • &quot; for quotation mark (")

Comments in XML

  • XML comments' syntax is similar to HTML: <!-- This is a comment -->

XML Naming Rules

  • Element names are case-sensitive.
  • Element names must start with a letter or an underscore.
  • Element names cannot start with "xml" (or XML, or Xml, etc.).
  • Element names can include letters, digits, hyphens, underscores, and periods.
  • Element names cannot contain spaces.
  • Any name can be used except the reserved word "xml".

XML Naming Conventions

  • Naming conventions are:
    • Lower case: <firstname>
    • Upper case: <FIRSTNAME>
    • Snake case: <first_name> (used in SQL databases)
    • Pascal case: <FirstName> (used by C programmers)
    • Camel case: <firstName> (used in JavaScript)

XML Attributes

  • Attribute values must always be quoted
  • Either single or double quotes can be used

ACT 1 & 2: XML and HTML Tasks

  • The XML file must contain a root, child, and sub-child.
  • The XML must contain at least 10 children and 3 sub-children.
  • Create a website with three pages (Home, Table, About).
  • The Homepage contains a preview of the website's content.
  • The Table contains data from the XML file.
  • About the developer.
  • All three pages must be connected.
  • The website theme must be connected to the XML file.

The XMLHttpRequest Object

  • The XMLHttpRequest object requests data from a web server.
  • It is a developer's dream because it allows:
    • Updating a web page without reloading it.
    • Requesting data from a server after the page has loaded.
    • Receiving data from a server after the page has loaded.
    • Sending data to a server in the background.

Sending an XMLHttpRequest

  • JavaScript syntax for using the XMLHttpRequest object involves creating a new object, setting up a callback function for when the state changes, opening a request to a file and sending the request.

XML DOM

  • The Document Object Model (DOM) defines a standard for accessing and manipulating documents.
  • The HTML DOM defines a standard way for accessing and manipulating HTML documents, presenting them as a tree-structure.
  • The XML DOM defines a standard way for accessing and manipulating XML documents, presenting them as a tree-structure.

XML Parser

  • Major browsers have a built-in XML parser to access and manipulate XML.
  • The XML DOM (Document Object Model) defines the properties and methods for accessing and editing XML.
  • Before an XML document can be accessed, it must be loaded into an XML DOM object.
  • Modern browsers have a built-in XML parser that can convert text into an XML DOM object.

XML and XSLT

  • XSLT transforms an XML document into HTML.
  • XSLT (eXtensible Stylesheet Language Transformations) is the recommended style sheet language for XML.
  • XSLT can add/remove elements and attributes, rearrange and sort elements, perform tests, and make decisions about which elements to hide and display.
  • XLST uses XPath to find information in an XML document

XML and XPath

  • XPath is a major element in the XSLT standard.
  • XPath can be used to navigate through elements and attributes in an XML document.
  • XPath uses path expressions to select nodes or node-sets in an XML document.
  • XPath is used in JavaScript, Java, XML Schema, PHP, Python, C and C++.

The AJAX Introduction

  • AJAX = Asynchronous JavaScript And XML.
  • AJAX not a programming language.
  • AJAX is combination of:
    • A browser built-in XMLHttpRequest object (to request data from a web server)
    • JavaScript and HTML DOM (to display or use the data)
  • AJAX updates web pages asynchronously, updating parts of a web page without reloading the whole page.

How AJAX Works

  • AJAX involves an event occuring in a web page.
  • An object is created by J avaScript and sends a request to a web server
  • The server processes the request, then sends a response back to the web page
  • The response is read by J avaScript
  • Proper action (like page update) is performed by J avaS cript

AJAX and the XMLHttpRequest Object

  • The keystone of AJAX is the XMLHttpRequest object which is supported by all modern browsers.
  • The XMLHttpRequest object exchanges data with a server behind the scenes, updating parts of a web page without reloading the whole page.

XMLHttpRequest Object Properties

  • The object methods are:
    • new XMLHttpRequest() creates a new XMLHttpRequest object
    • abort() cancels the current request
    • getAllResponseHeaders() and getResponseHeader() return header information
    • open(method, url, async, user,psw) specifies the request
    • send() Sends the request to the server (used for GET requests)
    • send(string) Sends the request to the server (used for POST requests)
    • setRequestHeader() Adds a label/value pair to the header to be sent
  • Object properties:
    • Defines a function to be called when the readyState property changes. Also the onreadystatechangeProperty
    • readyState property holds the status of the XMLHttpRequest object and the onreadystatechange property defines a function to be executed when the readyState changes.
    • Returns the response data as a string
    • object.The responseXML property returns the response data as XML data
    • object holds the status-number of a request i.e. OK etc,
    • object thestatusText property holds the status-text (e.g. OK or Not Found)

AJAX Requests

  • The object is used to exchange data with a server via the methods:
    • xhttp.open("GET", "ajax_info.txt", true);
    • xhttp.send();
  • To specify the type of request use the open(method, url, async)

GET vs POST

  • GET is simpler and faster than POST and can be used in most cases.
  • POST should be used when:
    • a cached file is not an option
    • you're sending a large amount of data to the server
    • you're sending user input (which can contain unknown characters).

Asynchronous Requests

  • Server requests should be sent asynchronously: xhttp.open("GET", "ajax_test.asp", true);
  • Asynchronous sending the J avaS cript doesn't have to wait for the server response, it can execute other scripts deal with the response after the response is ready.
  • When readyState is 4 and status is 200, the response is ready.

ACT 3 XML Task

  • Create an XML file that stores animal names.
  • Save some pictures of the animals.
  • Save the address of each image file within XML as an element.
  • Create a webpage with a textbox and a button.
  • Designate the button to trigger and show the image of the animal corresponding to the content of the textbox.
  • Show "No Data found" replacing the image content if no animal/data is found.

JSON: JavaScript Object Notation

  • JSON is a data format that represents data as a set of JavaScript objects.
  • JSON was invented by JS guru Douglas Crockford of Yahoo!.
  • It is natively supported by all modern browsers and supported by old ones with libraries.
  • JSON is rising in popularity due to its simplicity and ease of use.

XML vs JSON

  • XML Pros:
    • standard open format
    • can represent almost any general kind of data
    • easy to read
    • lots of tools exist for working with XML
  • XML Cons:
    • bulky syntax/structure makes files large and decreases performance
    • can be hard to shoehorn data into XML format
    • JavaScript code to navigate the XML DOM is bulky
  • in JavaScript, you can create a new object without creating a class
  • the object can have methods (function properties) that refer to itself as this
  • can refer to the fields with .fieldName or ["fieldName"] syntax
  • field names can optionally be put in quotes

Equivalent data example

  • Compare sample formats:

Browser JSON methods

  • Methods for browser compatibility are in the table:
  • How to use Ajax to fetch data that is in JSON format.
    • You can then call JSON.parse on it to convert it into an object

ACT 4 XML Task

  • Create an XML file that stores product name, category, price, and image location.
  • Create a web page similar to Lazada, with a search bar (textbox), and two dropdown boxes:
    • Category = "ALL" -Sort by Price = "Ascending"
  • The default page should display all products, filtered when you type text in the search bar.
  • The two dropdown boxes should also provide their purpose/function.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

XML: Linguagem de Marcação Extensível
20 questions
Intro to XML
10 questions

Intro to XML

CommodiousBigBen6639 avatar
CommodiousBigBen6639
Use Quizgecko on...
Browser
Browser