updatecli icon indicating copy to clipboard operation
updatecli copied to clipboard

XML: Unable to reference Attribute instead of Value.

Open zonorti opened this issue 1 year ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

I am trying to read or write an XML Attribute using updatecli. But not finding the value. According to XPath it's a valid query. Error:

SOURCES
=======

xml
---
ERROR: ✗ cannot find value for path "/a/b/@MyVal" from file "test.xml"
ERROR: ✗ cannot find value for path "/a/b/@MyVal" from file "test.xml"
Pipeline "Test XML" failed
Skipping due to:
	sources stage:	"cannot find value for path \"/a/b/@MyVal\" from file \"test.xml\""

See further for example files.

Expected Behavior

Source: reads 1 from XML Target: writes 1 into MyVal of /a/c

Steps To Reproduce

test.xml

<a>
  <b MyVal="1">1</b>
  <c MyVal="2">2</c>
</a>

updatecli.yaml

name: Test XML

sources:
  xml:
    name: Read Attribute from XML
    kind: xml
    spec:
      file: test.xml
      path: "/a/b/@MyVal"

targets:
  xml:
    name: Change Attribute in XML
    kind: xml
    spec:
      file: test.xml
      path: "/a/c/@MyVal"

run updatecli diff

Environment

- OS: macOS Sonoma 14.4.1
- updatecli: 0.85.0

Anything else?

No response

zonorti avatar Oct 14 '24 16:10 zonorti

Thanks for opening this pull request, Updatecli is currently using the library github.com/beevik/etree and it appears that there is a limitation on the attribute syntax

cfr github.com/beevik/etree/#51

olblak avatar Oct 14 '24 20:10 olblak

Thanks for a swift reply, @olblak! We are trying to change csproj file from dotnet here. Would it make sense for us to experiment with another XML library? Is this something that could get merged? Otherwise using shell is probably way to go, right?

zonorti avatar Oct 15 '24 08:10 zonorti

Thanks for a swift reply, @olblak! We are trying to change csproj file from dotnet here. Would it make sense for us to experiment with another XML library? Is this something that could get merged? Otherwise using shell is probably way to go, right?

We could use another golang library if you know one, that's something we did for the yaml plugin.

olblak avatar Oct 15 '24 09:10 olblak

It seems to be supported in antchfx/xmlquery, but I am not sure if it's helpful on the writing side.

zonorti avatar Oct 28 '24 15:10 zonorti

Hey thanks, for sharing that library. I am not familiar with it. After a quick look, it may be difficult to use for updating xml files versus fetching information from a XML I'll try to investigate

olblak avatar Nov 04 '24 10:11 olblak