segmentio / xml-parser

simple non-compliant xml parser for nodejs
101 stars 36 forks source link

xml.trim is not a function #20

Open dcsan opened 8 years ago

dcsan commented 8 years ago

getting this error on trying to parse a file:

/Users/dc/dev/rikai/botmaker/oped/node_modules/xml-parser/index.js:23
  xml = xml.trim();
            ^

TypeError: xml.trim is not a function
    at parse (/Users/dc/dev/rikai/botmaker/oped/node_modules/xml-parser/index.js:23:13)
    at Object.<anonymous> (/Users/dc/dev/rikai/botmaker/oped/outliner.js:6:11)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:142:18)
    at node.js:939:3

its an OPML file like this:

<?xml version="1.0"?>
<opml version="2.0">
  <head>
    <title>My First Outline</title>
    <ownerTwitterScreenName>dcsan</ownerTwitterScreenName>
    <ownerName>david 'DC' collier</ownerName>
    <ownerId>http://twitter.com/dcsan</ownerId>
    <dateModified>Tue, 02 Aug 2016 05:04:30 GMT</dateModified>
    <expansionState>1,3</expansionState>
    <lastCursor>0</lastCursor>
    </head>
  <body>
    <outline text="stuff:">
      <outline text="text: here" created="Tue, 02 Aug 2016 03:17:55 GMT"/>
      <outline text="answers:" created="Tue, 02 Aug 2016 03:18:01 GMT">
        <outline text="two" created="Tue, 02 Aug 2016 03:18:06 GMT"/>
        <outline text="three" created="Tue, 02 Aug 2016 03:18:07 GMT"/>
        </outline>
      <outline text="one" created="Tue, 02 Aug 2016 03:18:05 GMT"/>
    </outline>
  </body>
</opml>
ya-kostik commented 8 years ago

Hello, I think this may have happened because you gave Buffer instead of a String. Try to convert buffer to a string or read a file as UTF-8

const xml = fs.readFileSync('./my.xml', 'utf8');