processing / processing/p5.js

`p5.XML.listChildren()` inserts `#text` unexpectedly

Open
#7,047 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:IO Bug
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)
p5.js version

1.9.3

Web browser and version

Chrome 124.0.6367.208

Operating system

macOS 14.4.1

Steps to reproduce this
Steps:
  1. Call myXML.listChildren().
  2. View the returned array.
Snippet:
/*
<?xml version="1.0"?>
<animals>
  <mammal id="0" species="Capra hircus">Goat</mammal>
  <mammal id="1" species="Panthera pardus">Leopard</mammal>
  <mammal id="2" species="Equus zebra">Zebra</mammal>
  <reptile id="3" species="Caretta caretta">Turtle</reptile>
</animals>
*/

let myXML;

// Load the XML and create a p5.XML object.
function preload() {
  myXML = loadXML('assets/animals.xml');
}

function setup() {
  noCanvas();

  // Get the names of the element's children as an array.
  let children = myXML.listChildren();

  // Print the array to the console.
  // Desired: ["mammal", "mammal", "mammal", "reptile"]
  // Actual: ["#text", "mammal", "#text", "mammal", "#text", "mammal", "#text", "reptile", "#text"]
  print(children);
}

Here's the sketch for reference.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the p5.XML.listChildren() entry point and reproduce the behavior with the linked sketch or the XML snippet in the issue. Compare the returned names with the desired array, ensuring whitespace-only text nodes are not included; done means the result contains only the four element names.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.