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

x
?
Solved

Including XML Schema in XML File with MSXML4 DOM

Posted on 2004-10-06
2
Medium Priority
?
419 Views
Last Modified: 2013-11-19
Hi,

No doubt its been asked before, but I haven't been able to find a solution to this problem anywhere, so here goes.

I have an XML Schema saved in a file, lets say "schema.xsd".  I am generating the XML document that this schema will validate dynamically from within Visual Basic 6 with MXSML4.  Now, I need to put a reference to the schema onto the root element of the XML I am generating. eg:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:schema.xsd">
      --- rest of XML document ---
</root>

This needs to be done within the DOM as I generate the XML.  How do I do this?  MSDN suggests using XMLSchemaCache but that doesn't work, and I can't find any other way.

Any suggestions?
0
Comment
Question by:nintoid
[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
2 Comments
 
LVL 26

Accepted Solution

by:
rdcpro earned 400 total points
ID: 12241922
The XMLSchemaCache is simply a way of validating XML documents against a locally cached copy of a schema (which might be better than depending on loading it from a public location specified in the XML).  But to answer your question, you use the createNode() method to create an attribute node scoped to the schema instance namespace, then add the node to the attributes collection of the root element.

Dim oAttrNode As IXMLDOMAttribute

Set oAttrNode = xmlDoc.createNode(2, "xsi:noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance")
oAttrNode.Value = "file:schema.xsd"

Set oRootNode = xmlDoc.documentElement
oRootNode.setAttributeNode oAttrNode


Note that this does not automatically cause the XML document to be validated!  That will only happen when the XML is parsed with these attributes, and the validateOnParse property is set.  You then have to check for parseErrors.

Regards,
Mike Sharp
0
 

Author Comment

by:nintoid
ID: 12246270
Thanks Mike, that worked perfectly!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 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