Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@xml-tools/simple-schema
Advanced tools
This package includes three elements:
With npm:
npm install @xml-tools/simple-schema
With Yarn
yarn add @xml-tools/simple-schema
Please see the TypeScript Definitions for full API details.
Defining a Schema:
const schema = {
name: "people",
required: true,
cardinality: "single",
attributes: {},
elements: {
person: {
name: "person",
required: false,
cardinality: "many",
attributes: {
eyeColor: {
key: "eyeColor",
required: false,
value: ["grey", "blue", "green", "red"],
},
},
elements: {
name: {
cardinality: "single",
required: true,
name: "name",
attributes: {},
elements: {},
},
},
},
},
};
A Simple XML Text
// A Sample XML Text
const xmlText = `<people>
<person eyeColor="violet">
<name>Daenerys Targaryen</name>
</person>
</people>`;
Performing Validations
const { parse } = require("@xml-tools/parser");
const { buildAst } = require("@xml-tools/ast");
const { validate } = require("@xml-tools/validation");
const { getSchemaValidators } = require("@xml-tools/simple-schema");
const { cst, tokenVector } = parse(xmlText);
const xmlDoc = buildAst(cst, tokenVector);
const schemaValidators = getSchemaValidators(schema);
const issues = validate({
doc: xmlDoc,
validators: {
attribute: [schemaValidators.attribute],
element: [schemaValidators.element],
},
});
console.log(issues[0].msg); // Expecting one of <grey,blue,green,red> but found <violet>
console.log(issues[0].position); // { startOffset: 46, endOffset: 53 }
Using Content Assist APIs
const { getSuggestions } = require("@xml-tools/content-assist");
const { getSchemaSuggestionsProviders } = require("@xml-tools/simple-schema");
const schemaSuggestionsProviders = getSchemaSuggestionsProviders(schema);
const suggestions = getSuggestions({
text: xmlText,
offset: 47, // within the eyeColor quoted value
providers: {
attributeValue: [
schemaSuggestionsProviders.schemaAttributeValueCompletion,
],
attributeName: [schemaSuggestionsProviders.schemaAttributeNameCompletion],
elementName: [schemaSuggestionsProviders.schemaElementNameCompletion],
},
});
console.log(suggestions[0]); // { text: 'grey', label: 'grey' }
console.log(suggestions[1]); // { text: 'blue', label: 'blue' }
Please open issues on github.
See CONTRIBUTING.md.
FAQs
XML Simple Schema
We found that @xml-tools/simple-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.