Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to get an xml tag automatically in xml file

Posted on 2001-06-22
10
304 Views
Last Modified: 2013-11-19
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.
0
Comment
Question by:vmandem
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6218493
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.
0
 

Author Comment

by:vmandem
ID: 6218744
can you give me an example please how to do in visualbasic in order to get the header info.

Thanks for your quick response.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6218831
I would open the XML file as a text file, read each line in and build the HTML.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:Hornet241
ID: 6218923
>>>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.
0
 

Author Comment

by:vmandem
ID: 6219451
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.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6219499
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
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6221291
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
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6221522
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
0
 

Author Comment

by:vmandem
ID: 6221947
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
0
 
LVL 3

Accepted Solution

by:
Hornet241 earned 50 total points
ID: 6223139
acperkins
   Thanks but I had checked before I read your comment and your are right, I found the syntax to create the DOCTYPE node but I get an invalid operation error when I try.  All the documentation I found also says it is read only.  Oh well I found alot of other interesting information on the way so it wasn't a complete loss.

vmandem,

If your using this in a string variable anyway then you could just do this, it's not to pretty and limited but it should work

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

str1 = str1 & m_objDOMpeople.xml

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 65
Cordova Camera plugin fails 2 140
RUNRMTCMD from AS/400 12 69
php mysql check email already in database. (second check) 7 66
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question