dynamically generating XML prob

Discussion in 'XML' started by natkhatbandar, Dec 29, 2004.

  1. Hi,
    I am generating an XML document dynamically using DOM.
    I am creating an element using IXMLDOMDocument::createElement() and
    then calling IXMLDOMElement::appendChild() for the parent element. For
    attributes, I use IXMLDOMDocument2::createAttribute() and then

    My problem is that for each of the elements, an additional "xmlns"
    attribute is added with no value (xmlns=""). How can I avoid getting
    this extra attribute from being inserted? Note that I am not putting a
    prefix for the element names.

    --- Sample XML generated-----------------
    <MyRoot xmlns="http://www.xyz.com/abc"
    xsi:schemaLocation="http://www.xyz.com/abc abc.xsd">
    <MyElement1 xmlns="" attrib1="v1"/>
    natkhatbandar, Dec 29, 2004
    1. Advertisements

  2. Sounds as if you are using MSXML, with MSXML you should use
    createNode(1, 'element-name', 'namespaceURI')
    if you want to create elements in a namespace. If you use
    then the element is created in the null namespace and thus when the
    document is serialized the
    <element-name xmlns="">
    needs to be added to properly serialize the document.

    So you want (JScript syntax)
    var rootElement = xmlDocument.createNode(
    var myElement = xmlDocument.createNode(

    If you are not using MSXML but a W3C DOM Level 2 compliant
    implementation then you need to use
    var rootElement = xmlDocument.createElementNS(
    var myElement = xmlDocument.createElementNS(
    Martin Honnen, Dec 29, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.