1

Supposing I have an HTML document like what's below:

mypage.html

<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <table>
      <tbody>
       ...
       <tr>
         <td id="MY_ID">123</td>

How would I edit the element set to MY_ID? I've used the following command successfully when it was just the table in a document, but placing it in a larger document broke it:

xmlstarlet ed --update '//td[@id="MY_ID"]' --value '456' mypage.html
T145
  • 1,415
  • 1
  • 13
  • 33
  • 1
    You say: "placing in a larger document" . Could that larger document be in a namespace? For using namespaces in xmlstarlet, see: https://stackoverflow.com/a/44186555/3710053 – Siebe Jongebloed Jun 10 '21 at 08:39
  • @SiebeJongebloed I've tried using the `/_:` syntax before, and it doesn't work. – T145 Jun 10 '21 at 19:31

1 Answers1

0

Your td element needs to be closed (</td>) for it to be valid XML. You can try the following it here :

<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <table>
      <tbody>
       ...
       <tr>
         <td id="MY_ID">123</td>
         <td> id="NOTMYID">127</td>
        </tr>
      </tbody>
    </table>
  </body>
</html>

Using your own expression: //td[@id="MY_ID

StarshipladDev
  • 1,166
  • 4
  • 17
  • I've fixed the typo in the main post; sorry about that. Testing my expression on that site you reference does show that it's working, so why isn't the value being changed? – T145 Jun 10 '21 at 04:33