Click to See Complete Forum and Search --> : converting and entire text document to XML
ccampbell
September 20th, 2001, 01:28 PM
I am looking for a way to convert an entire text document to XML.
Does anyone know how this is possible? Is there a script that I can
run or can I create a file similar to a DTD to create the xml file
from a text file? Any information, code, or light on this subject
would be greatly appreciated. Thanks in advance
eahmed
October 16th, 2001, 06:52 PM
Converting a text document into and XML file is very easy. Start by creating an XML structure - something like this...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<document>
</document>
</root>
Then insert the document into the
element in the XML file. For example, if your document is made up of a sentance like "CodeGuru is a developer's site by & for developers", then the XML file would look like this...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<document>
CodeGuru is a developer's site by & for developers
</document>
</root>
BUT - there is a small problem. The problem is related to the quote and ampersand (&) characters in the sentance - these are considered special control characters by most XML processors. You can still use characters like the ampersand and quote - although not directly. Replace the ampersand with & and the quote with " and you're set! The final version of the XML document looks like this...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<document>
CodeGuru is a developer"s site by & for developers
</document>
</root>
The DTD for the XML file I've been working with follows...
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT document (#PCDATA)>
<!ELEMENT root (document)>
The DTD basically says that the XML document has a "document" element that contains PCDATA contained within a "root" element.
You can easily write an application that work with simple file i/o to read the source document and then create the target XML document. If you're concerned about the format of the resulting XML file, you can create the XML document using the XML DOM or Microsoft's implementation of SAX which you can use to write out XML documents. Let me know if you need an example like this - I have one written in C++ that uses Microsoft's XML SAX implementation to write out an XML document.
Essam
__________________________________________________________
Author of JScript .NET Programming - Available Now!
http://www.designs2solutions.com/jsnetprg
Subramanianbinu
November 6th, 2001, 06:36 AM
Can you please send me the example your referring to ? Thanx
eahmed
November 8th, 2001, 05:44 PM
I just finnished writing a tutorial on using the Microsoft XML Parser to create XML documents - it may be posted soon.
Essam Ahmed
___________________________________________________
Author of JScript .NET Programming - Now Avaialble!
http://www.designs2solutions.com/jsnetprg
See how easy it is to:
o migrate from ASP to ASP .NET
o create a Web Service
o consume a Web Service from a Windows Forms app
o work with ADO .NET
o work with ADO in an ASP .NET application
o migrate from ADO to ADO .NET
o ...and more!
o Accepting subscriptions for a newsletter on the .NET Framework and JScript .NET - Subscribe Today!
http://www.designs2solutions.com/jsnetprg
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.