Solved

Changing DOCTYPE using DOM - MSXML parser 3.0

Posted on 2001-07-24
10
1,129 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 25 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
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!

 
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

Suggested Solutions

Title # Comments Views Activity
Post xml via PHP Soap Client 3 74
XSLT XML 4 33
read an xml file in perl 2 69
TSQL XML Namespaces 7 38
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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