JSXMLBuilder does not read attributes correctly
XML Library/Tools for JavaScript
Brought to you by:
pjjt
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.
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.
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.
Oh and thank you for letting me know and posting the fix.