Menu

#1 JSXMLBuilder does not read attributes correctly

open
nobody
5
2011-03-31
2011-03-31
Anonymous
No

I parse some XML using REXML and then I am using a JSXMLBuilder to get the value of an attribute. The XML it is having difficulties with is...

<OC SP="0" ID="2780748300" NM="Brian Jones" PID="2318918702" OD="1.800" FP="1.8"/>

On this element, if I do 'element.attribute("ID")', I get 2318918702 not 2780748300.

Discussion

  • Nobody/Anonymous

    The problem is in the ParseAttribute function...

    if (str.indexOf(Attribute + "='")>-1) var Attr = new RegExp(".*" + Attribute + "='([^']*)'.*>");

    You need to add a space to make sure that the value for "PID" is not used for the "ID" attribute...

    if (str.indexOf(" " + Attribute + "='")>-1) var Attr = new RegExp(".* " + Attribute + "='([^']*)'.*>");

    I did this for the two lines in ParseAttribute and it now works.

     
  • Peter Tracey

    Peter Tracey - 2011-08-02

    Ah. I'll create a new release one of these days. There is another bug I found, can't remember what it was but it was easy to fix and I'm sure I'll find it when I look at the code again.

     
  • Peter Tracey

    Peter Tracey - 2011-08-02

    Oh and thank you for letting me know and posting the fix.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.