129 lines
4.1 KiB
Markdown
129 lines
4.1 KiB
Markdown
# XML
|
||
|
||
Extensible Markup Language (**XML**) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable.
|
||
|
||
- Utilized often in [BBEdit](obsidian://open?vault=Coding%20Tips&file=Computers%2FMac%20OS%20X%2FBBEdit) for CLMs.
|
||
|
||
- [This](https://www.w3schools.com/xml/xml_tree.asp) is a fantastic article explaining how an XML diagram which we learned about in software engineering directly translates to the XML code that is used by the system. This is why diagrams are so important in software engineering overall.
|
||
- This [website](https://www.hezhengda.io/xml-file-from-quantum-espresso/) discusses how to extract XML files from quantum espresso.
|
||
- XML formatter --> freeformatter.com
|
||
|
||
For example, this is the XML diagram:
|
||
![[Pasted image 20221208133914.png]]
|
||
|
||
And this would be the XML code:
|
||
```
|
||
<?xml version="1.0" encoding="UTF-8**"**?>
|
||
<bookstore>
|
||
<book category="cooking">
|
||
<title lang="en">Everyday Italian</title>
|
||
<author>Giada De Laurentiis</author>
|
||
<year>2005</year>
|
||
<price>30.00</price>
|
||
</book>
|
||
<book category="children">
|
||
<title lang="en">Harry Potter</title>
|
||
<author>J K. Rowling</author>
|
||
<year>2005</year>
|
||
<price>29.99</price>
|
||
</book>
|
||
<book category="web">
|
||
<title lang="en">Learning XML</title>
|
||
<author>Erik T. Ray</author>
|
||
<year>2003</year>
|
||
<price>39.95</price>
|
||
</book>
|
||
</bookstore>
|
||
|
||
```
|
||
|
||
Wait so hold on just a second, wouldn't this have applications in quantum??
|
||
|
||
- apparently, [this](https://github.com/photonquantum/actix-xml) is a XML extractor for actix-web a framework that is used in Rust
|
||
|
||
![[Pasted image 20230901124958.png]]
|
||
|
||
### XPATH
|
||
A query language for navigating in XML document or extract elements in HTML documents
|
||
|
||
[XPath Generator](https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbDNpRmQ5eUJ6amJvRFliRkFfcFI3Tk00RFNhQXxBQ3Jtc0tudXpjSVJ3RUE3TUhFTWtNMFIyVnlhaVFDUm5aTS1wRmZZVnVtdGlabVVPcDJ1Vkd5cnU0QkFINFZEeGR4T1VJX3lJM2tEVkx2ZDYyV3lkVlVHTnViN2RTc2J6WjE4c3MyMWt4aU9ZOUJnS0lvMnE5WQ&q=https%3A%2F%2Fwww.easycodeforall.com%2FXPathUtility.jsp&v=U-MZJ6rbqi4)
|
||
|
||
|
||
### XSL/XSLT
|
||
|
||
XSL - eXtensible Stylesheet Language
|
||
- a styling language for XML
|
||
|
||
XSLT - XSL Transformations
|
||
- transforms XML documents into other formats like HTML
|
||
|
||
```xml
|
||
<?xml-stylesheet type = "text/xsl" href = "student".xml?>
|
||
|
||
<class>
|
||
<student>
|
||
<firstname> Graham </firstname>
|
||
<lastname> Hall </lastname>
|
||
<nickname> Garry </nickname>
|
||
</student>
|
||
</class>
|
||
```
|
||
|
||
|
||
```xsl
|
||
<xsl:stylehseet verion = "1.0"
|
||
xmins:xml = "http://www.w1.org/1999/XML/tranform">
|
||
|
||
<xml.template match = "/class">
|
||
<html>
|
||
<body>
|
||
<h2> Student List < /h2>
|
||
<table border = "1">
|
||
<tr bgcolor="lightgreen">
|
||
<tr> First Name </tr>
|
||
<tr> Last Nam </tr>
|
||
<tr> Nick Name </tr>
|
||
</tr>
|
||
|
||
<xsl: for-each select = "student">
|
||
<tr>
|
||
<td><xsl:value-of select = "firstname"/>
|
||
</td>
|
||
<td><xsl:value-of select = "lastname"/>
|
||
</td>
|
||
<td><xsl:value-of select = "nickname"/>
|
||
</td>
|
||
</body>
|
||
</html>
|
||
<xml:template>
|
||
</xsl:stylesheet>
|
||
```
|
||
|
||
Output:
|
||
![[Pasted image 20230901130417.png]]
|
||
|
||
|
||
#### XML Scheme:
|
||
|
||
```
|
||
<class>
|
||
<student>
|
||
<firstname>
|
||
</class>
|
||
```
|
||
|
||
It is **Valid** if it follows an XML Schema or XSD (XML Scheme definition)
|
||
XML Scheme describes the structure of an XML document, written in XML
|
||
|
||
[XSD Generator ](https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbXVlTHJCdm96UjRDSzJHOVZwVklhRTF1YWNZZ3xBQ3Jtc0ttVE5qc3BGV3d5d3NoUDBKUXYwZFpBbFdRX2xJODZkcDVsWDRqLXhobE9yYXVsRDFMbW5HWndkcmpaNk5zLXZxZ1VVQVRPZ0RWd0w1ZXR0ZEIzdnEzRFNYUE9SeGpTSzgxcnpKUm5NdWF5WWFWWHdlZw&q=https%3A%2F%2Fwww.freeformatter.com%2Fxsd-generator.html&v=1BjmZHRHDv0)
|
||
|
||
Example:
|
||
|
||
```
|
||
<xs:schema xmins:xs="http://www.w3.org">
|
||
<xs:element name="class">
|
||
<xs:complexType>
|
||
<xminselement name ="student> maxOccurs="Unbounded" minOccurs="0">
|
||
|
||
```
|
||
Ensure that it is valid. |