R
RobG
I'm working with XML files that sometimes use a default namespace,
unfortunately there doesn't seem to be an elegant way of dealing with
them. In some cases I need to modify part of the expression to include
a random namespace, e.g. change:
/LandXML/Parcels/Parcel
into something like:
/xx:LandXML/xxarcels/xxarcel
Sometimes the expression starts with // so I've been using the
following regular expression:
expr = expr.replace(/(\/+)/g,'$1xx:');
which works fine in most cases. However, sometimes the expression
includes an attribute value that has slashes. In that case, I don't
want to modify the attribute value's slash. e.g. at the moment,
/LandXML/Parcels/Parcel[@name="79a/SP199095"]
is converted to:
/xx:LandXML/xxarcels/xxarcel[@name="79a/xx:SP199095"]
Modifying the attribute value means that the result will be wrong. Is
there a regular expression that will only modify slashes outside
square brackets?
An alternative is to fix the namespace when building the expression,
which is less elegant than conditionally modifying the expression in
the evaluator function.
unfortunately there doesn't seem to be an elegant way of dealing with
them. In some cases I need to modify part of the expression to include
a random namespace, e.g. change:
/LandXML/Parcels/Parcel
into something like:
/xx:LandXML/xxarcels/xxarcel
Sometimes the expression starts with // so I've been using the
following regular expression:
expr = expr.replace(/(\/+)/g,'$1xx:');
which works fine in most cases. However, sometimes the expression
includes an attribute value that has slashes. In that case, I don't
want to modify the attribute value's slash. e.g. at the moment,
/LandXML/Parcels/Parcel[@name="79a/SP199095"]
is converted to:
/xx:LandXML/xxarcels/xxarcel[@name="79a/xx:SP199095"]
Modifying the attribute value means that the result will be wrong. Is
there a regular expression that will only modify slashes outside
square brackets?
An alternative is to fix the namespace when building the expression,
which is less elegant than conditionally modifying the expression in
the evaluator function.