{"record":{"id":"b9a7ecf555aeb4d9","repo":"iOfficeAI/OfficeCLI","slug":"xml-is-required-for-setattr-format-name-value","errorCode":null,"errorMessage":"--xml is required for setattr (format: name=value)","messagePattern":"--xml is required for setattr \\(format: name=value\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/RawXmlHelper.cs","lineNumber":232,"sourceCode":"                        node.AddAfterSelf(el);\n                    affected++;\n                    break;\n\n                case \"replace\":\n                    if (xml == null) throw new ArgumentException(\"--xml is required for replace\");\n                    var replaceFragment = ParseFragment(xml, xDoc);\n                    node.ReplaceWith(replaceFragment.ToArray());\n                    affected++;\n                    break;\n\n                case \"remove\" or \"delete\":\n                    RequireParent(node, \"remove\");\n                    node.Remove();\n                    affected++;\n                    break;\n\n                case \"setattr\":\n                    if (xml == null) throw new ArgumentException(\"--xml is required for setattr (format: name=value)\");\n                    var eqIdx = xml.IndexOf('=');\n                    if (eqIdx <= 0) throw new ArgumentException(\"setattr format: name=value\");\n                    var attrName = xml[..eqIdx];\n                    var attrValue = xml[(eqIdx + 1)..];\n\n                    // Handle namespaced attributes (e.g. w:val)\n                    var colonIdx = attrName.IndexOf(':');\n                    if (colonIdx > 0)\n                    {\n                        var prefix = attrName[..colonIdx];\n                        var localName = attrName[(colonIdx + 1)..];\n                        var ns = nsManager.LookupNamespace(prefix);\n                        if (ns != null)\n                            node.SetAttributeValue(XName.Get(localName, ns), attrValue);\n                        else\n                            node.SetAttributeValue(attrName, attrValue);\n                    }\n                    else","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/RawXmlHelper.cs#L214-L250","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nRawXmlHelper.Execute(root, xpath, \"setattr\", null);\nRawXmlHelper.Execute(root, xpath, \"setattr\", \"w:val\");  // no =value\n\n// after\nRawXmlHelper.Execute(root, xpath, \"setattr\", \"w:val=center\");\nRawXmlHelper.Execute(root, xpath, \"setattr\", \"val=1\");","handlingStrategy":"validation","validationCode":"if (action.Equals(\"setattr\", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(xml))\n    throw new ArgumentException(\"--xml is required for setattr (format: name=value)\");\n\nRawXmlHelper.Execute(rootElement, xpath, action, xml);","typeGuard":null,"tryCatchPattern":"try\n{\n    RawXmlHelper.Execute(rootElement, xpath, \"setattr\", xml);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"--xml is required for setattr\"))\n{\n    Console.Error.WriteLine(\"For setattr, provide 'attributename=value' in the xml parameter.\");\n}","preventionTips":["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."],"tags":["xml","xpath","openxml","argument","raw-set","attribute"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}