Adding a namespace to an xml file

S

Shawn

Hi!
I've spent several hours finding a solution to this problem without any
luck. Hopefully someone here can provide me with an answer.

When I run this code I get an error saying: "Reference to undeclared
namespace prefix: 'esu'."
My question is simple: How do I add a namespace??
This is what the namespace should look like:
<esu:institusjoner xmlns:esu="http://www.utdanning.no/schema/institusjon/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.utdanning.no/schema/institusjon/
C:\schemas\schema_institusjon.xsd">

Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")

Set root = xmldoc.createNode("element", "esu:myroot", "")
xmldoc.appendChild(root)

Set node_1 = xmldoc.createNode("element", "esu:user", "")
xmldoc.documentElement.appendChild(node_1)

Set node_2 = xmldoc.createNode("element", "esu:id", "")
node_2.Text = "1"
node_1.appendChild(node_2)

Set node_3 = xmldoc.createNode("element", "esu:name", "")
node_3.Text = "Shawn"
node_1.appendChild(node_3)

xmldoc.save(server.mappath("xml.xml"))


Thanks,
Shawn
 
C

Chris Hohmann

Shawn said:
Hi!
I've spent several hours finding a solution to this problem without any
luck. Hopefully someone here can provide me with an answer.

When I run this code I get an error saying: "Reference to undeclared
namespace prefix: 'esu'."
My question is simple: How do I add a namespace??
This is what the namespace should look like:
<esu:institusjoner xmlns:esu="http://www.utdanning.no/schema/institusjon/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.utdanning.no/schema/institusjon/
C:\schemas\schema_institusjon.xsd">

Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")

Set root = xmldoc.createNode("element", "esu:myroot", "")
xmldoc.appendChild(root)

Set node_1 = xmldoc.createNode("element", "esu:user", "")
xmldoc.documentElement.appendChild(node_1)

Set node_2 = xmldoc.createNode("element", "esu:id", "")
node_2.Text = "1"
node_1.appendChild(node_2)

Set node_3 = xmldoc.createNode("element", "esu:name", "")
node_3.Text = "Shawn"
node_1.appendChild(node_3)

xmldoc.save(server.mappath("xml.xml"))

http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml2nd_pro_v4_0tyr.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top