dynamically generating XML prob

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • natkhatbandar@yahoo.com

    #1

    dynamically generating XML prob

    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 IXMLDOMDocument 2::createAttrib ute() and then
    IXMLDOMElement: :setAttributeNo de().

    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"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="http://www.xyz.com/abc abc.xsd">
    <MyElement1 xmlns="" attrib1="v1"/>
    ..
    ..
    </MyRoot>
    -----------------------------------------


    Thanks in advance.

  • Martin Honnen

    #2
    Re: dynamically generating XML prob



    natkhatbandar@y ahoo.com wrote:

    [color=blue]
    > 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 IXMLDOMDocument 2::createAttrib ute() and then
    > IXMLDOMElement: :setAttributeNo de().
    >
    > 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?[/color]

    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
    createElement(' element-name')
    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.cre ateNode(
    1,
    'MyRoot',
    'http://www.xyz.com/abc'
    );
    var myElement = xmlDocument.cre ateNode(
    1,
    'MyElement1',
    'http://www.xyz.com/abc'
    );

    If you are not using MSXML but a W3C DOM Level 2 compliant
    implementation then you need to use
    var rootElement = xmlDocument.cre ateElementNS(
    'http://www.xyz.com/abc',
    'MyRoot'
    );
    var myElement = xmlDocument.cre ateElementNS(
    'http://www.xyz.com/abc',
    'MyElement1'
    );

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    Working...