Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing DOCTYPE using DOM - MSXML parser 3.0

Posted on 2001-07-24
10
Medium Priority
?
1,144 Views
Last Modified: 2008-03-10
Environment
-----------

Windows NT/2000 server/workstation, Visual Basic 6.0, MSXML parser 3.0

Need
----

I need to change the DTD reference on an XML file. I need to do this programmatically using MSXML 3.0.

I tried making use of the doctype property of DOMDocument. But it's read only and I can't change and write the new DTD.

Since I am adding more data to an XML file, I also need to change the DOCTYPE reference to a new DTD file, which I am not able to do.

Any help is appreciated.

Thanks!
Guru
0
Comment
Question by:guruprasad031298
[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
  • 4
  • 4
  • 2
10 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6314273
The only way to change the <!DOCTYPE>  value in the DOM is to parse out the string and replace the value.

ODOM.Load "File.xml"

StrXML = ODOM.xml

StrXML = Replace(strXML, "DTD STRING TO REPLACE", "NEW STRING")

Set ODOM = Nothing

ODOM.LoadXML = StrXML

0
 
LVL 10

Accepted Solution

by:
Yury_Delendik earned 75 total points
ID: 6316685
Or using XSL:
  var source = new ActiveXObject("Msxml2.DOMDocument");
  source.async = false
  source.load("source.xml");

  var stylesheet = new ActiveXObject("Msxml2.DOMDocument");
  stylesheet.async = false
  stylesheet.load("change_dtd.xsl");

  var result = new ActiveXObject("Msxml2.DOMDocument");
  result.async = false
  result.validateOnParse = false;

  source.transformNodeToObject(stylesheet, result);

--------- change_dtd.xsl:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         version="1.0" >

<xsl:output method="xml" indent="yes" doctype-system="another.dtd" />

<xsl:template match = "/"><xsl:copy-of select="." /></xsl:template>

</xsl:stylesheet>



0
 
LVL 1

Author Comment

by:guruprasad031298
ID: 6317719
Yury,

Your answer makes logical sense. But when I run my application, I get an error,

"The stylesheet doesn't contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.". The run time error is '-2147467259 (80004005)'.

Do you have any idea why this is happening.

Thanks!
Guru
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 6319213
Try to print stylesheet.parseError.reason. Maybe path to file is wrong.

but I think... XSL only:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0" >

<xsl:output method="xml" indent="yes" doctype-system="another.dtd" />

<xsl:template match = "/"><xsl:copy-of select="." /></xsl:template>

</xsl:stylesheet>

another part of javascript for translation :-)
0
 
LVL 1

Author Comment

by:guruprasad031298
ID: 6319276
I don't think it's a problem with your code. I ran the transformnodetoobject sample available on the MSDN site
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmmthtransformnodetoobject.asp and I get the same error.

Could it be something to do with the MSXML 3.0 parser I am using.
0
 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 6319361
Hmmm. It's okay for me.
I wrote it in "change_dtd.js" file.
0
 
LVL 1

Author Comment

by:guruprasad031298
ID: 6319859
Yury,

As you mentioned the path to the file was wrong. But now I have a crazy problem.

If I use the transformNodeToObject method, the resultant DOMDocument doesn't have any contents, like in your code

xmlDoc.transformNodeToObject stylesheet, result

where result is a DOMDocument.

Instead if I use the transformNode method and capture the output, the string has the contents which I could save to a file. But as per MSDN documentation, MSXML parser saves the encoding to UTF-16, but not the default as specified in the XML as well as the XSL file.

So, I can't open the resultant XML file using MSXML.

Do you have any pointers why the 'transformNodeToObject' method doesn't get any results. I don't get any errors though.

Thanks.
0
 
LVL 10

Expert Comment

by:Yury_Delendik
ID: 6321063
It may be validation problem. Wrong DTD path (source document DTD path and destination document one) or invalid XML structure.

Encoding:
<xsl:output method="xml" indent="yes" doctype-system="another.dtd" encoding="UTF-8" />

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6322169
Parse that puppy...  you would be done by now!
0
 
LVL 1

Author Comment

by:guruprasad031298
ID: 6338103
I will accept this answer. I am still trying to find a reason why transferNodeToObject doesn't work for me.

Thanks!
Guru
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

609 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