How to create an HTML page with a given XML file? - html

I've read and converted a file into a XML file. The file format will always be as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<family>
<person>
<id>I1#</id>
<name>Joao</name>
<father>I2#</father>
<mother>I3#</mother>
</person>
<person>
<id>I5#</id>
<name>Joao</name>
<father>I2#</father>
<mother>I3#</mother>
</person>
</family>
With this i need to create a simple HTML page, that would still keep the XML format and maybe even allow me to style, for example, the tags colors, so they would still be showing in a different color like on the XML. I've tried putting everything inside a but it just shows everything in black.

You can also try using xslt where you can define how you want to transform each XML tag to HTML.
https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor/Basic_Example

Related

Parsing an XML file with multiple <?xml> tags using Node.js/Express/xml2js

my problem is as follows:
I'm downloading an xml file using express.js and then parsing that file. Right now it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE item [ ]>
<item lang="EN" >
<country>US</country>
<doc-number>123123123</doc-number>
<kind>A1</kind>
<date>20191017</date>
</item>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE item [ ]>
<item lang="EN" >
<country>US</country>
<doc-number>0938409384</doc-number>
<kind>A2</kind>
<date>20191018</date>
</item>
I'm using the xml2js library and I'm having trouble getting the entire document. My code looks something like this
parseString(xml, function (err, result) {
console.log(obj);
})
The XML only outputs only the first piece of xml. How can I parse this so I can get an array of <item>s?
My first idea is to loop through the doc as a string and split it based on <?xml version="1.0" encoding="UTF-8"?> and parse the data that way.
Thanks!
I do not think you can have more than one xml declarations for a single xml document. Additionally, a root element must always be present.
Therefore, the xml document you have provided is 2 separate xml documents, in principle. Most parsers or APIs would probably reject it, as not well formed.
Do you have any control over how the document is generated? If yes, you should ensure that a single xml declaration and a single root element will be present. Something similar to:
<?xml version=“1.0” encoding=“utf-8”>
<items>
<item>…</item>
<item>…</item>
</items>
If you do not have any control on the generation, you should probably split it and parse the documents separately, or concatenate them and generate a document similar to the one above.

Flex how to specify the application encoding?

<?xml version="1.0" encoding="utf-8"?>
<s:Application
is that xml attribute encoding="utf-8" making the whole application in utf-8?, also the input forms and others? or where do I specify it?
The encoding you are referring to is the xml document encoding.
This tells the editor/compiler what the character definitions are.
Go ahead and change it to utf-16
What you want it the restrict property on the textinput

Is it possible to make a selectable drop down menu using data from an XML file?

I'm trying to create a directory for an address book, and I was wondering if it would be possible to create a selectable drop down menu that would pull the contact data from an XML file. The ideal way I would want it is to have all of the names of the contacts in the drop down menu, and when one is selected the rest of the information would pop up above the drop down, such as Address, Phone Number, and Email.
Either use a server-side language such as PHP to extract the data from the XML and insert it into the HTML document, or use AJAX to pull the XML file to the client then use JavaScript to process it and insert it into the DOM.
There should be libraries/frameworks/plugins/whatever available to parse XML using whatever language you need, if you know how to insert stuff into the HTML document (in the case of PHP) or into the DOM (in the case of JavaScript), you can do this easy.
From what I understand you have an XML document. Using XSLT you create an XHTML file from your XML and that you can display in your browser (XHTML is HTML that is conform to XML rules).
If that is the case then, yes, you can make links using XSLT. But the data needs to be in your XML source file and not in some database.
There is an article that describes it: http://www.ibm.com/developerworks/xml/library/x-tipxslt/index.html
You could attach an XSL to the XML using something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
... actual XML content...
If applying the XSL on the XML outputs an HTML page with JavaScript, you can get the actual result.
Outputting JavaScript is a bit of a pain because of character escaping but it can be done.

How to convert this XML into HTML?

I have this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Diary>
<Event EventName="J.Edgar" Classification="2011 Movies" EventStart="2012-03-19T07:00:00+00:00" EventEnd="2012-03-19T08:00:00+00:00" />
<Event EventName="Titanic" Classification="1997 Movies" EventStart="2012-03-19T09:00:00+00:00" EventEnd="2012-03-19T10:00:00+00:00" />
....
</Diary>
How can I create an automatic table (with HTML and CSS)? these details of EventName, etc.. are automatic and I need something Dynamic for it.
I tried using W3 tutorials but didn't manage to get anything out of it. This XML file looks different than regular ones as well.
Please let me know if you have an idea.
Many thanks!
You can use StyleSheets http://www.w3.org/Style/XSL/WhatIsXSL.html. There should be utilities in each programming language to transform XML with XSL.

SSI and XSL: xml displayed as a blob

I am building a menu and have it set up so that I use a standard <!--#include virtual = "myDoc.xml" --> SSI tag to include my xml document. The xml document includes the xsl document with <?xml-stylesheet type="text/xsl" href="myOtherDoc.xsl"?>. For some reason the xsl document is not working. The xml is being displayed as a blob.
Unfortunately your XSL transform won't work like that. You'd have to send the XML document alone to the browser where the built in xsl transformer would then reference the stylesheet and perform the transform.
What you've got is an HTML page already being rendered and you're including the XML as just a chunk of xml rendered into the output stream, but the browser won't know to transform it because it doesn't have the:
<?xml-stylesheet type="text/xsl" href="myOtherDoc.xsl"?>
...PI at the start of the page. Remember these are processed by the browser not the server.
You would need to transform the XML server side e.g.
<!-- #include virtual="doMenuXform.asp" -->