iOfficeAI/OfficeCLI · error · ArgumentException
--xml is required for setattr (format: name=value)
Error message
--xml is required for setattr (format: name=value)
What it means
Thrown when the action is 'setattr' but the xml argument is null. For setattr, the xml parameter carries the attribute specification in name=value format (not an XML fragment). Without it, there is no attribute to set. The error message includes the expected format: 'name=value'.
Source
Thrown at src/officecli/Core/RawXmlHelper.cs:232
node.AddAfterSelf(el);
affected++;
break;
case "replace":
if (xml == null) throw new ArgumentException("--xml is required for replace");
var replaceFragment = ParseFragment(xml, xDoc);
node.ReplaceWith(replaceFragment.ToArray());
affected++;
break;
case "remove" or "delete":
RequireParent(node, "remove");
node.Remove();
affected++;
break;
case "setattr":
if (xml == null) throw new ArgumentException("--xml is required for setattr (format: name=value)");
var eqIdx = xml.IndexOf('=');
if (eqIdx <= 0) throw new ArgumentException("setattr format: name=value");
var attrName = xml[..eqIdx];
var attrValue = xml[(eqIdx + 1)..];
// Handle namespaced attributes (e.g. w:val)
var colonIdx = attrName.IndexOf(':');
if (colonIdx > 0)
{
var prefix = attrName[..colonIdx];
var localName = attrName[(colonIdx + 1)..];
var ns = nsManager.LookupNamespace(prefix);
if (ns != null)
node.SetAttributeValue(XName.Get(localName, ns), attrValue);
else
node.SetAttributeValue(attrName, attrValue);
}
elseView on GitHub (pinned to 1ced45e900)
Solutions
- Provide the attribute specification as 'name=value' in the xml parameter, e.g. 'w:val=center' or 'val=1'.
- Namespaced attributes use prefix:localname format, e.g. 'w:val=center' — the prefix is resolved against CommonNamespaces.
- If you meant to set element content (not an attribute), use a different action (append/replace) with an XML fragment.
Example fix
// before RawXmlHelper.Execute(root, xpath, "setattr", null); RawXmlHelper.Execute(root, xpath, "setattr", "w:val"); // no =value // after RawXmlHelper.Execute(root, xpath, "setattr", "w:val=center"); RawXmlHelper.Execute(root, xpath, "setattr", "val=1");
Defensive patterns
Strategy: validation
Validate before calling
if (action.Equals("setattr", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(xml))
throw new ArgumentException("--xml is required for setattr (format: name=value)");
RawXmlHelper.Execute(rootElement, xpath, action, xml); Try / catch
try
{
RawXmlHelper.Execute(rootElement, xpath, "setattr", xml);
}
catch (ArgumentException ex) when (ex.Message.Contains("--xml is required for setattr"))
{
Console.Error.WriteLine("For setattr, provide 'attributename=value' in the xml parameter.");
} Prevention
- For setattr, the xml parameter holds 'name=value', not an XML fragment.
- Namespaced attributes use 'prefix:localname=value' (e.g. 'w:val=center').
- Validate the name=value format before calling Execute.
When it happens
Trigger: RawXmlHelper.Execute(rootElement, xpath, "setattr", null). XPath matched at least one element, code entered the setattr case, xml == null. Note: for setattr, 'xml' is misnamed — it actually holds 'attrName=attrValue', not an XML fragment.
Common situations: Caller invokes raw-set with action=setattr but omits --xml. Caller provides the attribute name without a value (e.g. just 'w:val' instead of 'w:val=center'). Caller assumes setattr takes separate name and value arguments instead of a single name=value string.
Related errors
- setattr format: name=value
- --xml is required for append
- --xml is required for prepend
- --xml is required for insertbefore
- --xml is required for insertafter
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/b9a7ecf555aeb4d9.
Report an issue: GitHub.