So I tried to use F# XML parsing post on the following xml (from uclassify API):
<?xml version="1.0" encoding="UTF-8" ?>
<uclassify xmlns="http://api.uclassify.com/1/ResponseSchema" version="1.01">
<status success="true" statusCode="2000"/>
<readCalls>
<classify id="cls1">
<classification textCoverage="1">
<class className="happy" p="0.912929"/>
<class className="upset" p="0.0870707"/>
</classification>
</classify>
</readCalls>
</uclassify>
The code is something like:
let doc =
Xdocument.Load file
doc.Element(xn "uclassify")
.Element(xn "readCalls")
.Element(xn "classify")
.Element(xn "classification")
.Element(xn "class").Attribute(xn "p")
This does not work!!! Seems it can't get the Parsing done. Yet removing the attribute xmlns="http://api.uclassify.com/1/ResponseSchema" version="1.01"
makes it work:
let doc =
Xdocument.Load file
let test = IO.File.ReadAllText(file).Replace("xmlns=\"http://api.uclassify.com/1/ResponseSchema\" version=\"1.01\"","")
XDocument.Parse(test)
doc.Element(xn "uclassify")
.Element(xn "readCalls")
.Element(xn "classify")
.Element(xn "classification")
.Element(xn "class").Attribute(xn "p")
Note this problem seems related to Why must I remove xmlns attribute .... So the question is why must I remove the xmlns attribute ? What should I use to parse xml that have an xmlns attribute ?
Thank you