?
Solved

Changing DOCTYPE using DOM - MSXML parser 3.0

Posted on 2001-07-24
10
Medium Priority
?
1,135 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
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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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…
Suggested Courses

752 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