We can define custom XML namespace, which needs to be unique name and with customized structure.
-
We can associate css style for the XML elements like below.
<?xml-stylesheet type="text/css" href="businesscard.css" ?>
-
Nodes can be applied with custom css styling using the XML tag name directly like below.
Name {
color: blueviolet;
}
-
we can use custom attribute type and associate it with css to display custom styling.
<phone type="mobile" primary="super-important">(415) 555-4567</phone>
can be associated with css styling of
phone[primary]::after {
content: " (" attr(primary) ")";
}
this will result to displayed in
(65)123 - 456 (super important)
/BusinessCard/Name
/BusinessCard/Name/text()
/BusinessCard/phone
Take note that in xpath, referencing list index start from 1, not like 0 from other langagues
/Businesscard/phone[1]
/BusinessCard/phone[last()]
/BusinessCard/Name[contains(text(), 'Richard')]
/BusinessCard/phone[@type]
(or)
//phone[@type]
/BusinessCard/phone[@type='work']
(or)
//phone[@type='work']
/items/item[type='Coffee']/photo
- eXtensible Stylesheet Language Transformations
- Different than CSS - applies templates to XML data
- Written using XML syntax itself
- can transorm XML into almost anything
- can perform operations directly on the data.
- more at https://wwww.w3.org/TR/xslt
In below example, we are getting source element(SimpleTag) and replace with whatever we define in this XSLT template (in this case some html).
If there is an issue of Cross-Origin Request Blocked on firefox testing, temporarily disable the setting during testing.
- Provide way to contstrain XML document content
- Specify what kind of content can appear and where
- Can be included in XML file, or be external to document
- Relatively simple to write, but not powerful
Example: Below basically declare the rules that BusinessCard element needs to follow.
-
There should be Name.
-
followed by 1 or more phone.
-
followed by optional email.
<!ELEMENT BusinessCard (Name, phone+, email?)
Example2: This means phone number is characters
-
Additonally phone has attribute type with 4 values which are required.
<!ELEMENT phone (#PCDATA)>
<!ATTLIST phone type (mobile | work | fax | home) #REQUIRED>
- Alternative way of specifying rules to DTDs
- Provide way to constrain XML document content
- Written in XML syntax
- Similar to DTDs, but more powerful and robust
- Finar level of control than DTDs allow
- Schema and XML files are always stored separately
Testing using https://www.xmlvalidation.com/
- go to https://www.xmlvalidation.com/
- upload XML file
- tick
Validate against external XML schema
checkbox and click Validate. - upload XSD file and validate it.