diff --git a/pkg/ottl/ottlfuncs/README.md b/pkg/ottl/ottlfuncs/README.md index 10f5acd833be..2820f5e17884 100644 --- a/pkg/ottl/ottlfuncs/README.md +++ b/pkg/ottl/ottlfuncs/README.md @@ -1293,7 +1293,7 @@ Examples: The `RemoveXML` Converter returns an edited version of an XML string with selected elements removed. `target` is a Getter that returns a string. This string should be in XML format. -If `target` is not a string, nil, or cannot be parsed as XML, `ParseXML` will return an error. +If `target` is not a string, nil, or is not valid xml, `RemoveXML` will return an error. `xpath` is a string that specifies an [XPath](https://www.w3.org/TR/1999/REC-xpath-19991116/) expression that selects one or more elements to remove from the XML document. diff --git a/pkg/ottl/ottlfuncs/func_remove_xml.go b/pkg/ottl/ottlfuncs/func_remove_xml.go index f499be952748..bf12b09d9848 100644 --- a/pkg/ottl/ottlfuncs/func_remove_xml.go +++ b/pkg/ottl/ottlfuncs/func_remove_xml.go @@ -25,21 +25,21 @@ func NewRemoveXMLFactory[K any]() ottl.Factory[K] { func createRemoveXMLFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[K], error) { args, ok := oArgs.(*RemoveXMLArguments[K]) - if !ok { return nil, fmt.Errorf("RemoveXML args must be of type *RemoveXMLAguments[K]") } + if err := validateXPath(args.XPath); err != nil { + return nil, err + } + return removeXML(args.Target, args.XPath), nil } -// removeXML returns a `pcommon.String` that is a result of removing all matching nodes from the target XML. +// removeXML returns a XML formatted string that is a result of removing all matching nodes from the target XML. // This currently supports removal of elements, attributes, text values, comments, and CharData. func removeXML[K any](target ottl.StringGetter[K], xPath string) ottl.ExprFunc[K] { return func(ctx context.Context, tCtx K) (any, error) { - if err := validateXPath(xPath); err != nil { - return nil, err - } targetVal, err := target.Get(ctx, tCtx) if err != nil {