Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Note, if you're using @xmpp/client
or @xmpp/component
, you don't need to install @xmpp/xml
yourself.
npm install @xmpp/xml
or yarn add @xmpp/xml
const xml = require('@xmpp/xml')
const {xml} = require('@xmpp/client')
const {xml} = require('@xmpp/component')
There's 2 methods for writing XML with xmpp.js
const xml = require('@xmpp/xml')
const recipient = 'user@example.com'
const days = ['Monday', 'Tuesday']
const message = xml(
'message',
{to: recipient},
xml('body', {}, 1 + 2),
xml('days', days.map(day => xml('day', {}, day)))
)
Used in xmpp.js source code.
/** @jsx xml */
const xml = require('@xmpp/xml')
const recipient = 'user@example.com'
const days = ['Monday', 'Tuesday']
const message = (
<message to={recipient}>
<body>{1 + 2}</body>
<days>
{days.map(day => (
<day>${day}</day>
))}
</days>
</message>
)
Used in xmpp.js tests.
Requires a preprocessor but if you're already using Babel and/or need to write big chunks of XML it's a good choice. See our .babelrc for a configuration example.
The attrs
properties holds xml attributes for an element.
message.attrs.to // user@example.com
Returns the text value of an element
message.getChild('body').text() // '3'
Get child element by name.
message.getChild('body').toString() // <body>3</body>
Get children elements by name.
message.getChild('days').getChildren('day') // [...]
Get child element text value.
message.getChildText('body') // '3'
The attrs
properties holds xml attributes for an element.
message.attrs.type = 'chat'
Object.assign(message.attrs, {type: 'chat'})
Set the text value of an element
message.getChild('body').text('Hello world')
Adds text or element nodes to the last position. Returns the parent.
message.append(xml('foo'))
message.append('bar')
message.append(days.map(day => xml('day', {}, day)))
// <message>
// ...
// <foo/>
// bar
// <day>Monday</day>
// <day>Tuesday</day>
// </message>
Adds text or element nodes to the first position. Returns the parent.
message.prepend(xml('foo'))
message.prepend('bar')
message.prepend(days.map(day => xml('day', {}, day)))
// <message>
// <day>Tuesday</day>
// <day>Monday</day>
// bar
// <foo/>
// ...
// </message>
Removes a child element.
const body = message.getChild('body')
message.remove(body)
You can embed JSON anywhere but it is recommended to use an appropriate semantic.
/** @jsx xml */
// write
message.append(
<myevent xmlns="xmpp:example.org">
<json xmlns="urn:xmpp:json:0">{JSON.stringify(days)}</json>
</myevent>
)
// read
JSON.parse(
message
.getChild('myevent', 'xmpp:example.org')
.getChildText('json', 'urn:xmpp:json:0')
)
See JSON Containers
FAQs
XMPP XML for JavaScript
The npm package @xmpp/xml receives a total of 13,798 weekly downloads. As such, @xmpp/xml popularity was classified as popular.
We found that @xmpp/xml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.