Solved

How to get an xml tag automatically in xml file

Posted on 2001-06-22
10
301 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 52
Reading the Contents of a Directory In Access VBA 5 60
Grunt No Clean Targets 6 111
VB6 - Convert HH:MM into Decimal 8 53
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now