Solved

How to get an xml tag automatically in xml file

Posted on 2001-06-22
10
300 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
Comment Utility
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
Comment Utility
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
Comment Utility
I would open the XML file as a text file, read each line in and build the HTML.
0
 
LVL 3

Expert Comment

by:Hornet241
Comment Utility
>>>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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now