?
Solved

How to get an xml tag automatically in xml file

Posted on 2001-06-22
10
Medium Priority
?
308 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
[X]
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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 150 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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