Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add namespace to root item in builder #541

Open
quoininc-huudatran opened this issue Oct 31, 2019 · 1 comment · May be fixed by #559
Open

How to add namespace to root item in builder #541

quoininc-huudatran opened this issue Oct 31, 2019 · 1 comment · May be fixed by #559

Comments

@quoininc-huudatran
Copy link

Hi,

How do you add the namespace when creating the builder?

I have the following code that add the namespace, but doesn't have a good output:

        const xmlObj = {
            urlset: {
                $: { xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9' },
                _: urls
            }
        };
        const builder = new xml2js.Builder();
        return builder.buildObject(xmlObj);

It generates this weird thing at the bottom:

sitemap_1_xml

With the following code, I don't get the namespace:

        const builder = new xml2js.Builder({
            rootName: 'urlset',
            $: { xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9' }
        });
        return builder.buildObject(urls);

sitemap_2_xml

Any way to fix this?

Omega-Ariston added a commit to Omega-Ariston/node-xml2js that referenced this issue Feb 26, 2020
@rdupz
Copy link

rdupz commented Apr 19, 2023

Also interested in this. What's the best workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants