Reputation: 175
I have an XML data generated via Javascript in MarkLogic:
<Activities datatype="array">
<Activity>
<ActivityCrewSize>10</ActivityCrewSize>
<ActivitySeqNo>1</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
How can I remove the datatype information so it will just look like this:
<Activities>
<Activity>
<ActivityCrewSize>10</ActivityCrewSize>
<ActivitySeqNo>1</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
obj.Activities = [];
let act = {
'$type': 'Activity',
'$version': '0.0.1',
}
for (const item of activities) {
act.ActivityCrewSize = fn.normalizeSpace(hl.elementText(item, "CrewSize", true));
act.ActivitySeqNo = fn.normalizeSpace(hl.elementText(item, "SeqNo", true));
act.ActivityDesc = hl.elementText(item, null, true);
obj.Activities.push(act);
}
return obj;
Upvotes: 1
Views: 52
Reputation: 175
I was able to remove the data type information by converting the data using the Sequence.from
function in MarkLogic. Hope this may help anyone in the future.
Upvotes: 0
Reputation: 1257
If you need it short and simple, this may satisfy your requirements.
var _xml = '<Activities datatype="array"><Activity><ActivityCrewSize>10</ActivityCrewSize<ActivitySeqNo>1</ActivitySeqNo><ActivityDesc/></Activity></Activities>';
var _test = _xml.replace(/\sdatatype\=\".+\"/g,'');
alert(_test);
This will wildcard-remove ANY occurance of ' datatype="(anything)"' from your XML-String. https://jsfiddle.net/53817ofj/
If you need it a bit more complex, you may want to take a look at https://www.w3schools.com/xml/xml_parser.asp
Upvotes: 0
Reputation: 7368
You can Remove an attribute by name.
xmlDoc.getElementsByTagName("Activities")[0].removeAttribute('datatype');
<Activities datatype="array">
<Activity>
<ActivityCrewSize>10</ActivityCrewSize>
<ActivitySeqNo>1</ActivitySeqNo>
<ActivityDesc/>
</Activity>
</Activities>
Upvotes: 1