Xml to html linux

Linux.yaroslavl.ru

Для преобразования исходных документов в другие форматы используются языки описания преобразований и таблицы стилей. Существуют два языка для работы с таблицами стилей ( stylesheets ):

Язык семантики и описания стиля документа (DSSSL — Document Style Semantics and Specification Language) был создан для работы с документами в формате SGML и может работать с документами в формате XML, поскольку второй является подмножеством первого. В Sisyphus таблицы стилей DSSSL для работы с Docbook находятся в пакете docbook-style-dsssl.

Утилиты, использующие эти таблицы стилей, находятся в Sisyphus в пакете docbook-utils.

Пример 1. Преобразование XML-документа в формат HTML с использованием DSSSL-стилей

Расширяемый язык стилей (XSL — Extensible Style Language) — язык обработки стилей, созданный специально для работы с XML. Он позволяет преобразовывать документы из XML в HTML, RTF, а также в другие документы XML. Для преобразования XML-документов можно также пользоваться языком XSLT — XSL Transformations . В Sisyphus XSL-таблицы стилей для Docbook /XML находятся в пакете docbook-style-xsl.

Процессор, обрабатывающий XSL-таблицы стилей, находится в Sisyphus в пакете xsltproc.

Пример 2. Преобразование XML-документа в формат HTML с использованием XSL-стилей

xsltproc --xinclude -o html/ --param default.encoding \"KOI8-R\" /usr/share/xml/docbook/xsl-stylesheets/html/chunk.xsl file.xml

В этом примере используется стиль chunk , который создаёт отдельные html-файлы для каждого раздела в подкаталоге html. Параметр default.encoding указывает кодировку выходных файлов.

Подсказка

При использовании стиля docbook на выходе получится один большой html-файл со всем содержимым. Параметр default.encoding при этом не учитывается и в документе вместо букв будут их числовые обозначения. Такие документы корректно отображаются браузерами, просто занимают больше места, чем документы с кодировкой, например, koi8-r.

Опытным путем выяснено, что использование XSL-стилей даёт лучшие результаты, чем использование DSSSL-стилей.

linux samba mail postfix FreeBSD Unix doc linux howto ALTLinux PHP faq bind sendmail apache iptables firewall kernel rpm apt-get Slackware openssh Cisco debian vmware GNU oracle sun awk /etc/ passwd linux установка учебник книга скачать

Источник

Automatically convert XML to HTML with xsltproc and bash in Linux

After doing nmap, I often convert the XML output to HTML to view in browser.

xsltproc input.xml -o output.html

However, if I want to convert multiple xml files to html, I’ll have to type the command multiple times. That’s rediculously tiredsome. So I decide to write a simple bash file to automatically convert all the xml files in a folder into html files with the same names.

Читайте также:  Ms access для линукс

you have following files in /some_folder/

user@linux: ~/some_folder/ls File1.xml File2.xml File3.xml

After running the script, you will have the following file

user@linux:~/some_folder/convert_xml.sh File1.xml to File1.html File2.xml to File2.html File3.xml to File3.html

Don’t worry, the old fils are still there.

Here is my code. It is very basic, does not have the “-help” option, but it will do the work. You can convert directories other than the current directory by input while calling the script, like this:

user@linux: ~/ convert_xml.sh /some_dir/some_dir/some_dir
#!/bin/bash #convert all xml to html with the same name # $1 = directory #INTIALIZE VARIABLES p_directory="file_directory" file_list="file_list" #GET DIRECTORY if [ $# -eq 0 ] then p_directory="./" #get director=./ if no directory is inputed elif [ $# -eq 1 ] then p_directory=$1 #ADD "/" to the end of the directory if [ "$" != "/" ] then p_directory="$p_directory/" fi elif [ $# -gt 1 ] then echo \*ERROR\* echo Input only the directory exit 1 fi #GET FILE_LIST file_list=$(find $p_directory -type f -name "*.xml") #DO THE WORK echo "Directory: $p_directory" for file in $(echo $file_list); do p_full_name=$(basename $file) p_file_name="$" xsltproc $p_directory$p_full_name -o $p_directory$p_file_name.html echo "Convert $p_full_name to $p_file_name.html" done #remove var unset file_list unset p_directory

I’m pretty sure that there are more simple way to do this, but in the mean time, this is what I can come up with. Hope it is of some help to you. And if you have any suggestion, I’m all ear.

Источник

basics steps in converting xml file to html file

I would like convert a xml file to a html file. Where i can find a step by step tutorial (for linux) to do this in shell script, or which are the steps to follow. Sorry for the very basic question, but i am an absolute begginer on this. thanx

Do you actually want to convert it to HTML? Or to display the data on a web page? XML is a more flexible format for maintaining data, while HTML is used to DISPLAY and format data. Given that, you may want to explore XSLT as a way of applying a style to your XML data to get it to display nicely. But XSLT can be a little daunting for a newbie.

Читайте также:  Kes 10 sp1 mr1 linux

2 Answers 2

The basic tools to do this is XSLT.

XSLT is a language that you can use to describe how XML elements should be converted into HTML elements. Once you have an XSLT files that suits your need (you will have to write it), you can use the xsltproc utility to convert that XML files into HTML files.

How to write the XSLT transformation files depends on the exact kind of XML file you must translate. There are already-made XSLT-to-HTML transformation files for many formats, search for «[your format] xslt to html».

You can learn more about XSLT in W3Schools tutorials.

The xsltproc utility is available for most Linux distributions.

You can use XSLT to map XML tags to HTML tags or fragments. There is no step-by-step guide on how to do this since the exact XSLT stylesheet to create depends on both what your XML looks like and what you want your HTML to look like. Once you have your stylesheet you can use xsltproc (part of libxslt) from the command line, or you can use the XSLT facilities available to most programming languages.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Converting NMAP XML Files to HTML with xsltproc

Travis Phillips

NMAP is a wonderful network scanner and its ability to log scan data to files, specifically XML, helps quite a bit. This enables the scan data to be parsed by other tools such as Metasploit’s db_import or even NMAP’s own Zenmap GUI. While XML is great for parsing, it’s not really easy for humans to read. I have found several people are unaware of the fact that the NMAP XML file can also be converted into a nicely formatted HTML file via the use of a tool called xsltproc. Today I want to give a quick rundown of how to do that from start to finish using a Kali Linux VM and Metasploitable2 VM.

Читайте также:  Canon mf421dw драйвер linux

Lab Setup

The setup for this exercise used two lab VMs. One was a Kali VM, the other was a Metasploitable2 VM. The Metasploitable2 VM serves as a target to be scanned via NMAP from the Kali VM. The diagram below shows the configuration of the lab.

example 1

Scanning to Create the XML Scan Data File

From the Kali VM we want to scan all TCP ports on the Metasploitable2 VM and also run it with version detection and default scripts. I generally like to log in all data formats using the -oA [filename_prefix] switch and argument. If you are looking to only get the XML file then you could use the -oX switch instead. For this lab, I used the following command as root to run the scan:

example 2

Converting the XML File into an HTML File

This is where the xsltproc comes in. This tool can be used to convert the XML file into a nicely formatted HTML file. To perform this conversion, run the following command:

example 3

Viewing the Results

Now that we have the HTML file, it can be viewed in the web browser of your choice. The HTML file is designed to be a nice, clean, table-based report. Any scripts that produced output during the scan will be in the rows underneath the corresponding port and it will use a lighter color shade as the background color of the report. The screenshot below shows a sample of what this file looks like:

example 4

Conclusion

I hope you’ve enjoyed this blog post and learned something new today about NMAP XML files. If you’re interested in security fundamentals, we have a Professionally Evil Fundamentals (PEF) channel that covers a variety of technology topics. We also answer general basic questions in our Knowledge Center. Finally, if you’re looking for a penetration test, professional training for your organization, or just have general security questions please Contact Us.

Источник

Оцените статью
Adblock
detector