how do i parse a dtd file - c#

I want to parse a dtd file and use the info I get from that to create some classes. I know that I can convert it to a xsd and then parse it, but I was hoping to avoid that. Everything I find via google is to validate against a dtd. So I guess my question is: How do I parse a dtd file using c# or are there any tools or libraries out there that I can use? I should add that I'm using visual studio 2005.

You need an SGML parser: this thread should help you out: SGML parser .NET recommendations

Related

Building not valid XML Document (Name cannot begin with the '0' character) [duplicate]

This question already has answers here:
How to parse invalid (bad / not well-formed) XML?
(4 answers)
Closed last year.
I am trying to decode a custom xml config file in C#, but I am having troubles to create this file from the string I was able to get after my decode step.
After trying to build the xml, I got this error:
System.Xml.XmlException : 'Name cannot begin with the '0' character, hexadecimal value 0x30. Line 1, position 2.'
I know my xml is not a valid xml file because of its bad formatting but I would like to know is there is a way to build it anyways.
Format of the "xml file" :
<01_config.xml>
<name dataType="String">some_name</name>
<description dataType="String">some_description</description>
</01_config.xml>
If I replace 01_config.xml by config during debug, everything will work fine since it will become a valid xml file. But it will not be the good format for my config.
I guess I can still build the file without using the C# Xml building tools, but I would like to know if it's possible to do it with it in the first place.
XML component (element and attribute) names may not begin with a number.
Strictly speaking, this is a matter of the rules for being an XML document – well-formedness, not validity.
Reasons to correct this mistake
You want your document to be XML.
You want users of your document to be able to use the XML ecosystem of editors, parsers, validators, databases, transformation/selection languages, and libraries available in many languages.
You want the interoperability benefits of using a standard.
You want to participate in a community of users – tapping into, and contribute to, a collective body of knowledge to the community's mutual benefit.
Reasons to proceed with bad "XML"
You like the aesthetics of your "XML" variant because it's a "good format for my config".
Recommendation
Fix the mistake and work with standard XML.
See also
How to have an XML tag start with a number?
How to parse invalid (bad / not well-formed) XML?
I know my xml is not a valid xml file because of its bad formatting but I would like to know is there is a way to build it anyways.
Sure, you can build files that aren't well-formed XML, but then you won't be able to read them using XML tools.

XML schema generation library

I'm looking for some library that can parse XML or XSD files and create (even simple) GUI interface which is parsed schema compliant (some kind of a GUI editor for the schema). The user could fill it and save into XML file. I want to use it in my program as a module, so I can't use any external programs. I tried to find something in the Web, but still unlucky:(
Do you know any libraries such like that one? I want it in C# but if there are no such things written in .NET I could have a look at something from other language.
With a simple google search I came up with the following free tools:
XML Data Editor
Easy XML Editor

How to convert a System.IO.Packaging.Package to HTML?

Microsoft Word interoperability classes will let you get at a property called WordOpenXML. This represents a package that will be stored - zipped up - in a .docx file and can be opened by Microsoft Word. However, is there a way to convert this Package to other formats, notably HTML?
I read in an answer to an old question that "Word 2007 has an API that you can use to convert to HTML. [...] You can find documentation around the API, but I remember that there is a convert to HTML function in the API." I'm not 100% sure which API that guy is talking about but perhaps it's System.IO.Packaging.Package or something similar. I can't seem to find any "convert to HTML function"; does anyone know how you can convert a Package format Word document into HTML?
The API in question is probably the Save method on the document; when a file type of HTML is chosen, Word transforms the document into HTML, and applies the appropriate styling.
Chances are, given that the docx format is XML, there is an XSLT transformation of some sort going on; this is just speculation, but it's not far-fetched, as XSLT is commonly used to create HTML from XML.
That said, what you are looking for probably does not reside in the Package class, nor should it. The Package class is used for creating packages of content, not with the transformation of that content.
However, there's nothing stopping you from providing the transformation of that content; you can get the XML that is the basis of the Word document and then apply your own XSLT which would produce the HTML that you want.

How to convert XML to HTML using c# dynamically

How to upload XML file and generate Html file without XSLT file using C#...
LINQ to XML is one option. See also: Generating HTML using LINQ
The question is a little open-ended, but you might consider just writing a program that:
Deserializes the XML.
Having read in the XML, format the text.
Output the text using the standard in/out libraries in C#.
I don't know if this is the most efficient solution -- but I think it would work.

How to validate an XML document?

My C#/.NET application reads XML files that are manually edited by the users. The allowed elements and tags are described in the application's documentation. I'm using LINQ to extract data from the XML file.
Before extracting data from the XML file, I'd like to validate it to see if it has the expected structure. If not, it would be nice to have information about what is wrong so that I can give some feeback to the user.
What's the simplest way to do this in C#?
You can validate xml files against XSD.
First you have to create Xml Schema Definition file. See example
use XML Schema Definition Tool to create XSD from XMLfile
Use this code to validate input XML using corresponding XSD
Hope this will help...
EDIT
This article explains all possible ways to validate xml, using C#
How To Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET
IMO best option is to use XSD.
Validating Input Xml Data Files

Categories