Updated April 5, 2023
Introduction to Prolog XML
The prolog XML is a part of the document declaration and data management in a structure using tags. It is one of the markup languages which is based on the document-oriented concept. It is a declared document from start to end in format for usability and productivity. It is an optional part of the programming language to display and exchange data in a tag structured or format.
It is an optional document declaration part to sort prolog list data and display it in a given tag. It is used to exchange the data in the prolog programming language for simplification. It is optional and displays Metadata, declares structured data, and exchanges the prolog data structure data. It contains declaration data, document type, comment, and white space of the prolog code.
Syntax of Prolog XML
Given below is the syntax:
<?xml …>
Explanation:
- The XML contains the attribute and elements for empty elements.
- The XML mode creates case-sensitive language.
- The XML supports predefined entities such as a “less than”, “greater than”, etc.
- The XML mode includes underscore and colon in a namespace.
- The XML provides white space mode to preserve.
The basic prolog xml syntax shows below.
<?xml version = "1.0" encoding = "UTF-8"?>
The basic with standalone syntax shows below.
<?xml version = "1.0" standalone = "no"?>
The basic name space syntax shows below.
url: local/url/ name
It converts into prolog file syntax shows below.
xml( [version = "1.0", standalone = "no"]
It converts into prolog file syntax shows below.
xml( [version="1.0", standalone="no"],
[
doctype(public( "http://www.educba.com/" )),
namespace(
element(
[],
[
h. element(
i. [] )
j. ] )
k. )
l. ] ).
How does XML Works in Prolog?
Prolog comment works in the “pl” file.
Create a file with the “pl” extension.
Example:
main.pl
Insert data into the prolog file.
Then, save the object with value into a pl file.
The following commands can use for the “prolog XML” data of the list.
- First, write xml version and standalone value in the prolog file.
xml( [version="1.0", standalone="no"],
- Then, write down the document type with the required link and information.
doctype( svg, public( “-//W3C//DTD SVG 1.0//EN”, “http://www.educba.com/” ) ),
- Write the namespace for store elements.
- Write the elements of the required data, such as an image.
namespace( 'http://www.educba.com/svg', "",
element( svg,
[width="250", height="250"],
[
element( circle,
[cx="20", cy="20", r="18", style="fill: orange; stroke: yellow; stroke-width: 1"],
[] )
] )
Prolog comment works in the console:
- Open prolog console or interpreter.
- Set the directory path of the “pl” file.
- Use the given prolog file.
[main].
You can use the prolog console directly for programming.
Use the “prolog XML” syntax in the prolog console.
xml( [version="1.0", standalone="no"],
[
doctype( svg, public( "-//W3C//DTD SVG 1.0//EN", "http://www.educba.com/" ) ),
namespace( 'http://www.educba.com/svg', "",
element( svg,
[width="250", height="250"],
[
element( circle,
[cx="20", cy="20", r="18", style="fill: orange; stroke: yellow; stroke-width: 1"],
[] )
] )
)
] ).
Combine the working procedure of the “prolog if” function.
- Use the “main.pl” file.
- Use the given prolog console with the required directory path.
[main].
xml( [version="1.0", standalone="no"],
[
doctype(public( "http://www.educba.com/" )),
namespace(
element(
[],
[
element(
[] )
] )
)
] ).
- Use the command for “prolog XML” in the prolog console.
| ?- listing.
- The prolog console displays the below data for prolog XML.
xml([version = [49, 46, 48], standalone = [110, 111]], [doctype(public([104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 100, 117, 99, 98, 97, 46, 99, 111, 109, 47])), namespace(element([], [element([])]))]).
Examples of Prolog XML
Different examples are mentioned below:
Example #1
The basic prolog XML with empty element example and output shows below.
Use the following command in prolog pl file.
Code:
xml( [version="1.0", standalone="no"]).
Use the following command in prolog console.
Code:
| ?- [filename].
| ?- listing.
Output:
Example #2
The basic example and the output shows below.
Use the following command in prolog pl file and prolog console.
Code:
xml( [version="1.0", standalone="no"],
[
doctype( svg, public( "-//W3C//DTD SVG 1.0//EN", "http://www.w3.org/.../svg10.dtd" ) ),
namespace( 'http://www.w3.org/2000/svg', "",
element( svg,
[width="500", height="500"],
[
element( circle,
[cx="25", cy="25", r="24", style="fill: red; stroke: blue; stroke-width: 1"],
[] )
] )
)
] ).
Output:
Example #3
The basic example and the output shows below.
Use the following command in prolog pl file.
Code:
xml( [version="1.0", standalone="no"],
[
doctype( svg, public( "-//W3C//DTD SVG 1.0//EN", "http://www.w3.org/.../svg10.dtd" ) ),
namespace( 'http://www.w3.org/2000/svg', "",
element( svg,
[width="500", height="500"],
[
element( circle,
[cx="25", cy="25", r="24", style="fill: red; stroke: blue; stroke-width: 1"],
[] )
] )
)
] ).
Use the following command in prolog console.
Code:
| ?- [filename].
| ?- listing.
Output:
Example #4
With the standalone example and output shows below.
Use the following command in prolog pl file.
Code:
xml( [version="1.0", standalone="yes"],
[
doctype( svg, public( "-//W3C//DTD SVG 1.0//EN", "http://www.w3.org/.../svg10.dtd" ) ),
namespace( 'http://www.w3.org/2000/svg', "",
element( svg,
[width="500", height="500"],
[
element( circle,
[cx="25", cy="25", r="24", style="fill: red; stroke: blue; stroke-width: 1"],
[] )
] )
)
] ).
Use the following command in prolog console.
Code:
| ?- [filename].
| ?- listing.
Output:
Example #5
With empty element example and the output shows below.
Use the following command in prolog pl file.
Code:
xml( [version="1.0", standalone="yes"],
[
doctype(public( "http://www.educba.com/" )),
namespace(
element(
[],
[
element(
[] )
] )
)
Use the following command in prolog console.
Code:
| ?- [filename].
| ?- listing.
Output:
Example #6
With the encoding example and output shows below.
Use the following command in prolog pl file.
Code:
xml( [version="1.0", encoding="UTF-8", standalone="no"]).
Use the following command in prolog console.
Code:
| ?- [filename].
| ?- listing.
Output:
Conclusion
It is used for declaring data from start to end in format for usability and productivity. It exchanges the data in the prolog data structure simplification and maintain of the application. It creates attractive, sorted, and elegant prolog applications.
Recommended Articles
We hope that this EDUCBA information on “Prolog XML” was beneficial to you. You can view EDUCBA’s recommended articles for more information.