Closed fbertone closed 4 years ago
This makes sense to me in case you needed to do some extra parsing then the namespaces will be necessary.
just to add some info to the conversation: this regex
/<(\/?)(\w*):(\w*)((\s+[\w\d=":]+)*)\s*(\/?)>/g
matches open and closing tags, even short "self-closing" tags This can be used like
xml.replace(/<(\/?)(\w*):(\w*)((\s+[\w\d=":]+)*)\s*(\/?)>/g, '<$1$3$4$6>')
to remove all prefixes from tags (opening and closing) short explanation: $1 matches the initial closing '/' $3 matches the tag name ($2 is the prefix that we want to remove) $4 matches all inner attributes $6 matches the closing '/' for self-closing tags
However, this does not remove prefixes from attributes inside tags, so it does not yet guarantee a valid xml If we remove $4 we eliminate also attributes inside tags, that could solve the problem but at the cost of losing the attributes
A further manipulation to remove prefixes from attributes could be done with something like:
xml.replace(/(\s\w+:)(\w+=?"?\w*"?)/g, ' $2')
This matches all strings starting with a white space (' '), followed by a string, a ':' and another string, outputting just the second string and eliminating the first part. The issue with this regex is that it does not check if it is inside a tag, the side effect is that it could corrupt the values between tags if they match the rule. I don't know how to solve this issue at the moment
@hawkeye64 Do you agree with @fbertone? Because it looks reasonable to me.
Closing out old issue - PR would be great to sort this
Hi,
I'm trying to convert the XML sent as discovery response event into json (using x2js).
The camera originally sends this XML:
which is valid XML.
However, this XML gets filtered through parseSOAPString that filters out xml name spaces before firing the event. This transforms the original XML in
that unfortunately is no more valid XML because all the prefixes (s, d, wda, ecc) are now linked to nothing. This breaks the conversion of x2js (and possibly other libraries). The event should either send the original XML or parseSOAPString should clean up also all the prefixes to make a valid xml. To me either ways is fine, but I don't see why remove the names spaces in the first place. Apparently a similar thing appens here but in this case the raw XML is sent