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

attrNameProcessors and tagNameProcessors options for builder #181

Open
alexcrack opened this issue Mar 6, 2015 · 7 comments
Open

attrNameProcessors and tagNameProcessors options for builder #181

alexcrack opened this issue Mar 6, 2015 · 7 comments

Comments

@alexcrack
Copy link

For example we can add namespaces in builder and remove namespaces in parser (for the soap api). In result we have javascript objects without namespaces.

@Leonidas-from-XIV
Copy link
Owner

Sure, sounds sensible to me.

@jcsahnwaldt
Copy link
Contributor

Done: #462

@jasonperrone
Copy link

I am on 0.4.23 and I can't get this to work:

const builder = new xml2js.Builder({tagNameProcessors: [upperMe]});
builder.buildObject(myObj);

function upperMe(name) {
  return name.toUpperCase();
}

upperMe simply will not get called. What am I doing wrong?

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented Jan 7, 2023 via email

@jasonperrone
Copy link

Ah. I misunderstood the "done" above.

@jasonperrone
Copy link

@Leonidas-from-XIV without this feature, I can't seem to do what I need to.
Let's say I have this object:

{
  myRoot: {
    $: {
        'xmlns:abc': 'blahblah',
    }

    one: 'a',
    two: 'b',
    three: 'c'
  }
}

How can I have the builder build the tags with the abc: prefix so that I don't have to change the names of the attributes in my object? In other words, I want the XML to look like:

<abc:myRoot xmlns:abc='blahblah'>
  <abc:one>a</abc:one>
  <abc:two>b</abc:two>
  <abc:three>c</abc:three>
</abc:myRoot>

I honestly don't understand why it doesn't just do that since I did provide a namespace in the root tag.

So now I have to manually specify attributes in my object like 'abc:one' instead of one:.

@jasonperrone
Copy link

The only way I can figure to do it is:

  1. Start with my object.
  2. Use Builder to turn it into an XML string
  3. Use Parser to convert that String back into an object, and use the tagNameProcessors option on the parser.
  4. Use Builder again to turn that object into an XML string

Gotta be a better way.

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

No branches or pull requests

4 participants