Solved

Changing DOCTYPE using DOM - MSXML parser 3.0

Posted on 2001-07-24
10
1,123 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
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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. 
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

12 Experts available now in Live!

Get 1:1 Help Now