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.
Related
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
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.
Instead of modifying the stock templates that come with many suites, I'd like to extend the stock templates so when the stock template gets upgraded/updated with a new version, I can keep my own XSLT extension/modification of the stock XSLT and use to process with as well. Similar in function to a source code patch file or CSS inheritance.
For example, if the stock XSLT doesn't have enough spaces in the separation between footnotes when processing to HTML, I'd like to add my own XSLT for that footnote that adds a space.
In DocBook XSL stylesheets terms want you want to create is called a “customization layer”.
The basic idea is, put your customizations in a customizations.xsl or whatever file and then use your XSLT engine of choice to call that instead of the stock DocBook XSL driver file; like this:
xsltproc customizations.xsl my-docbook-source.xml
As far what exactly you put into the customizations.xsl file, if all you want to change is some of the user-configurable DocBook XSL params, it’s as easy as:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="html/docbook.xsl"/>
<xsl:param name="html.stylesheet" select="'corpstyle.css'"/>
<xsl:param name="admon.graphics" select="1"/>
</xsl:stylesheet>
And if you need to replace a whole template:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:import href="fo/docbook.xsl"/>
<xsl:template match="lineannotation">
<fo:inline font-style="italic">
<xsl:call-template name="inline.charseq"/>
</fo:inline>
</xsl:template>
</xsl:stylesheet>
So because instead of you directly calling the DocBook XSL driver file from the command line, you call your customization.xsl file and it needs to call the right DocBook XSL driver, then for the href values in, e.g., the <xsl:import href="html/docbook.xsl"/> elements, you just need to put the path to wherever the stock DocBook XSL stylesheets+driver are on your system.
For example, on a Debian system:
<xsl:import href="/usr/share/xml/docbook/stylesheet/docbook-xsl/html/docbook.xsl"/>
Caveats
If you need to make any changes to one of the templates in the stock stylesheets, you copy-paste the entire template into your customization layer and make your changes to the template there.
XSLT doesn’t give any more change-making granularity than that—e.g., you can’t have your layer contain just a two-line patch for part of a template. You have to copy in the whole template.
A consequence of that is, if the upstream maintainers change/fix some other part of original template you made a copy of, your customization layer is not going to pick up that change unless you re-copy the new upstream template in again and make your tweaks to it again.
But that’s probably not going to cause you any problems in practice because these days I think the upstream DocBook XSL templates don’t change very often.
Also note that some of the templates in the DocBook XSL stylesheets are huge—so your layer can end up being a relatively big file even if you only need to make a single-line patch
Yes it is possible for XSLT. Go for <xsl:apply-imports/>.
A template rule that is being used to override another template rule (see 6.4 Conflict Resolution for Template Rules) can use the xsl:apply-imports or xsl:next-match instruction to invoke the overridden template rule.
W3 apply-imports
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.
I just learnt about how to parse data in Xcode using NSXMLPARSER.
In order to do that, obviously, I will need xml files, but I am still a beginner with web programming.
I am having difficulties getting an xml file from a web page. I tried to convert html to xml using some softwares but I am still not getting the format I want.
The format that I want should be similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<Books>
<Book id="1">
<title>Circumference</title>
<author>Nicholas Nicastro</author>
<summary>Eratosthenes and the Ancient Quest to Measure the Globe.</summary>
</Book>
<Book id="2">
<title>Copernicus Secret</title>
<author>Jack Repcheck</author>
<summary>How the scientific revolution began</summary>
</Book>
</Books>
So how can I get a format like this from a webpage?
And one more thing: If someone knows about NSXMLPARSER using Xcode, is this the way to go to extract data from websites? I mean getting an xml file, putting it in the resource of our project and then extracting the data from it?
HTML is also XML. So if you want to extract data from any given website, you will need to get the HTML (the source of the page) and parse it "as is", then look for the data you need.
A simple website may look like this:
<html>
<head>
<title>My website</title>
</head>
<body>
<h1>welocome</h1>
Text
<p>paragraph</p>
</body>
</html>
As you can see, this is valid, wellformed XML. If you are interested in the <title>, parse this XML and look for the <title>-tag.
The problem is that browsers are not so strict with the wellformedness of HTML. A missing end tag for <p> is often tolerated. An XML-parser would normally not be that "nice" and produce an error.
Very often websites has rss/atom-feeds. These are pure XML and are always wellformed. These feeds are made for the purpose of getting data that is easily interpreted by XML parsers.