f# - How do I edit an XML file using type providers? -
i understand how retrieve data xml source using type providers. however, need modify particular part of xml , save disk. have tried assigning value node using <-
property read-only.
for example:
let doc = myxml.load filename doc.itemid.id <- "newid" // doesn't work doc |> savexml
there similar question json suggestion create new object, xml.
while researching question found can use .xelement
accessor reference mutable xelement
object. solution is:
let doc = myxml.load filename doc.itemid.xelement.element(xname.get "id").value <- "newid" // tada doc.xdocument.save(...)
note have use .xelement
accessor on parent if you're modifying leaf node. because leaf node's type primitive , doesn't have .xelement
accessor of own. slight shame, suppose makes life easier on other side when want read-only access value.
Comments
Post a Comment