Skip to main content
added 4 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Using Andrey Kislyuk's xq, an XML-parsing wrapper around jq (installed together with yq):

xq -x 'walk(del( .["@xmlns"]?, .["@xmlns:md"]? ))' file

This walks all nodes in the XML document structure and deletes all xmlns and xmlns:md attributes wherever these are found.

Given some input document,

<?xml version="1.0"?>
<root test="val">
  <md:EntityDescriptor xmlns="urn:_" xmlns:md="_"/>
</root>

... this would output

<root test="val">
  <md:EntityDescriptor></md:EntityDescriptor>
</root>

You get in-place editing with the --in-place or -i option.

Using Andrey Kislyuk's xq XML-parsing wrapper around jq (installed together with yq):

xq -x 'walk(del( .["@xmlns"]?, .["@xmlns:md"]? ))' file

This walks all nodes in the XML document structure and deletes all xmlns and xmlns:md attributes wherever these are found.

Given some input document,

<?xml version="1.0"?>
<root test="val">
  <md:EntityDescriptor xmlns="urn:_" xmlns:md="_"/>
</root>

... this would output

<root test="val">
  <md:EntityDescriptor></md:EntityDescriptor>
</root>

You get in-place editing with the --in-place or -i option.

Using Andrey Kislyuk's xq, an XML-parsing wrapper around jq (installed together with yq):

xq -x 'walk(del( .["@xmlns"]?, .["@xmlns:md"]? ))' file

This walks all nodes in the XML document structure and deletes all xmlns and xmlns:md attributes wherever these are found.

Given some input document,

<?xml version="1.0"?>
<root test="val">
  <md:EntityDescriptor xmlns="urn:_" xmlns:md="_"/>
</root>

... this would output

<root test="val">
  <md:EntityDescriptor></md:EntityDescriptor>
</root>

You get in-place editing with the --in-place or -i option.

Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Using Andrey Kislyuk's xq XML-parsing wrapper around jq (installed together with yq):

xq -x 'walk(del( .["@xmlns"]?, .["@xmlns:md"]? ))' file

This walks all nodes in the XML document structure and deletes all xmlns and xmlns:md attributes wherever these are found.

Given some input document,

<?xml version="1.0"?>
<root test="val">
  <md:EntityDescriptor xmlns="urn:_" xmlns:md="_"/>
</root>

... this would output

<root test="val">
  <md:EntityDescriptor></md:EntityDescriptor>
</root>

You get in-place editing with the --in-place or -i option.