I have DTD for XML files. I need a parser which should validate that DTD, should parse the XML file and on the fly it should create a html or perl script to present the contents of xml to the browser. Can anyone help me?
I can't give you a portable solution. I can tell you that I tried to use XML_DOM and XML:arser and XML::Writer to pursue the same chores. I ended up leaving the canned modules alone and wrote my own pattern matching routines to do the conversions to HTML. The standard XML modules were real resource eaters and were slow except on small files. The code I wrote was not trivial, but was fast and effective. I will say that I was able to do this because the XML files that I was converting to HTML were products of my organization and I knew what XML tags were possible. The tag universe was limited and I could account for all possible conversion needs.
GOOD LUCK with this one. I didn't find any easy solutions. I would be interested to hear how you work it out. Please post any successes or frustrations.
hi goBoating,
What should i do with DTD? Whenever i would like to parse a xml file i don't want to check it with dtd. Is there any way to do this? I m in confused state...
Well, I don't pretend to be an expert on this. 'just someone who did something similar and made it work. For what it is worth.........
If you can determine the total list of possible XML tags and structures, then you can decide how you want to convert them to HTML. Write a series of replacements for each item you want converted. The is some brute force involved here, but, the Perl regex engine is pretty quick. For instance, our internally created XML docs had table structures which I converted with this.
#-- code --#
sub convertTable
{
$buffer =~ s/<html:thead>//gis; [red]# did not need this - replace with null[/red]
$buffer =~ s/<html:tbody>/<table>/gis; [red]# start/end table tags[/red]
$buffer =~ s/<\/html:tbody>/<\/table>/gis;
$buffer =~ s/<html:th>/<th>/gis; [red]# table header[/red]
$buffer =~ s/<\/html:th>/<\/th>/gis;
$buffer =~ s/<html:tr>/<tr>/gis; [red]# table row[/red]
$buffer =~ s/<\/html:tr>/<\/tr>/gis;
$buffer =~ s/<html:td>/<td>/gis; [red]# table definition[/red]
$buffer =~ s/<\/html:td>/<\/td>/gis;
}
#-- end code --#
I read the entire file into $buffer and called that sub which made the XML to HTML replacements globally. This is just one of about 20 subs which did other conversions in a similar manner. I realize this looks like a lot of regex's, but, it runs reasonably quickly on files up to several hundred k.
If you can't get a list of the possible conversions you may have to do, then I guess you will need to parse the DTD to get translations and work from there. I was lucky. We did not need to validate the XML and I had a limited universe of tags to deal with. I hope you are equally lucky.
goBoating,
Thanx for ur tip. Which parser u r using? Can i use XML:OM parser to check well formness and validity? The xml file i m involving has so many tags.
If i pass a variable which holding a file content to a DOM parser object it is throwing long file name exception... Is it not possible to pass a variable rather than a xml file?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.