Link to home
Start Free TrialLog in
Avatar of vmandem
vmandem

asked on

How to get an xml tag automatically in xml file

I have visualbasic application which creates an xml file but when i open it in browser it doesn't have the xml tag
like:
<xml version 1:0>
 <!DOCTYPE PEOPLE SYSTME IMPORTER.DTD>


What i have to do in my application to get this, do i need to insert manually to get this, please help me on this.
Avatar of Dave_Greene
Dave_Greene

Your browser is designed to show XML in the way you're describing.  If you want to display the actual XML header information as it is in your XML document you will need to convert your XML to HTML...  essentially wrapping the XML with HTML, so it displays correctly.
Avatar of vmandem

ASKER

can you give me an example please how to do in visualbasic in order to get the header info.

Thanks for your quick response.
I would open the XML file as a text file, read each line in and build the HTML.
>>>What i have to do in my application to get this, do i need to insert manually to get this, please help
me on this.

If you are creating the XML from scratch in your app, you will have to manually enter that information.  Nothing else will be able to figure out this information for you.
Avatar of vmandem

ASKER

How can i pass it manually that is the question.

I put the whole thing in a string and i want to pass this string some how, the string looks like this:
Hornet

dim str1 as string

str1 =  "<?xml version='1.0'?><!DOCTYPE importFile SYSTEM 'importer.dtd'>"

I started building xml file like this:

Set objperson = m_objDOMpeople.createElement("PERSON")
  objperson.setAttribute "PERSONID", getNewID
  'm_objDOMpeople.documentElement.appendChild objperson
  m_objDOMpeople.appendChild objperson

I want to insert the string or the xml tag before building the structure. I hope you understood the problem, when i run in the browser i can see the tag.

Please help me on this.
Thnks.
Avatar of Anthony Perkins
vmandem,

The problem with your approach, as you no doubt have figured out already, is that when you do:
m_objDOMpeople.loadXML str  ' Assuming that m_objDOMpeople is DIMmed as DOMDocument

it fails because it is not a valid XML document as defined by the same DTD.

You probably have also figured out (unlike the <?xml version="1.0"?>) there is no way to add just the <!DOCTYPE ... > element using MSXML.

You have two solutions as I see it:
1. Load a valid XML template from a file or a string and modify with the MSXML.
2. Assume since you are coding it, that the document is valid and skip the DOCType altogether.

Hope this helps,
Anthony
Here is how to set the "<?xml version='1.0'?>"
I'm working on the DocType

     Set objperson = m_objDOMpeople.createElement("PERSON")
     objperson.setAttribute "PERSONID", getNewID
     m_objDOMpeople.appendChild objperson

     Dim TmpVer

     Set TmpVer = m_objDOMpeople.createProcessingInstruction("xml", "version=""1.0""")
     m_objDOMpeople.insertBefore TmpVer, m_objDOMpeople.childNodes.item(0)

I'll let you know how it's going, if you have the MSDN Library you can look up the DOMDocument or XMLDOMDocumentType Object
Hornet241,

Let me save you the work.  As I mentioned before, unlike the <?xml version="1.0"?>, there is no way to add the DOCTYPE using MSXML other than loading the whole XML document.  The DOM specifies the document interface's DOCTYPE property to be read-only, so there is no way to create a document type declaration.  Again, the only way round this is to load a shell document containing the declaration into the parser and proceed with dynamic methods from there.

Hope this clarifies,
Anthony
Avatar of vmandem

ASKER

Hornet

Let me try your option and i will let you know it works or not.

My issue is that the whole thing will not be saved to any directory as an .XML file, the whole thing i'm wrapping up in to a string variable, so if at all i want to use the html or other dynamic work, i have to save the file to a template or a file but my concern is i must pass the whole structure into a string, so i must include the tag xml version some how infront of the structure. Let me try your option and as u said i will look into the MSDN library also.

I'm thinking the acperkins comment also. Let me work on this. If you comeup with a solution please let me know.

Thankyou
ASKER CERTIFIED SOLUTION
Avatar of Hornet241
Hornet241
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial