这真的很奇怪,我担心我刚刚做了一些愚蠢的事情,但我无法弄清楚。
我将作为第一个参数传递None
给函数some
,但是当函数执行时,值为parentNode
null (我不关心它打印 null for None
,函数参数值 IS null not None
)。我最终在打印功能行上得到一个空引用错误,因为 parentNode 为空。我试图对 args 进行元组并更改顺序,但这没有帮助。我偷偷怀疑这与咖喱有关,但我不知所措......
对于公司问题,我必须用空字符串替换真实的 url 值,但如果有帮助,它是 xsd 的 url
这是代码:
#light
open System
open System.Xml
open System.Net
open System.Collections.Generic
type StartResult =
| Parameters of XsdParserParameters
| Xsd of Xsd
and Xsd(text) =
let rows = new List<string>()
member this.Text
with get() = text
member this.Rows
with get() = rows
and XsdParserParameters() =
let mutable url = ""
member this.Url
with get() = url
and set(value) = url <- value
member this.Start() =
try
use client = new WebClient()
let xsd = client.DownloadString(this.Url)
StartResult.Xsd(Xsd(xsd))
with e ->
StartResult.Parameters(this)
let processor () =
let parameters = XsdParserParameters()
parameters.Url <- ""
match parameters.Start() with
| StartResult.Parameters(xpparams) ->
//some error
()
| StartResult.Xsd(xsd) ->
let rec some (parentNode : XmlNode option) (node : XmlNode) =
let a = ()
for subNode in node.ChildNodes do
match subNode.LocalName with
| "complexType" ->
xsd.Rows.Add(
sprintf
"%O~%s~%d~%d~%s~%s~%O"
parentNode
subNode.Value
1
1
(subNode.Attributes.GetNamedItem("name").Value)
""
false)
some (Some(subNode)) subNode
| "sequence" ->
some parentNode subNode
| "element" ->
xsd.Rows.Add(
sprintf
"%O~%s~%d~%d~%s~%s~%O"
parentNode
subNode.Value
1
1
(subNode.Attributes.GetNamedItem("name").Value)
""
false)
some (Some(subNode)) subNode
| _ ->
()
let xdoc = new XmlDocument();
xdoc.LoadXml(xsd.Text)
some (None) (xdoc.DocumentElement)
processor()
printfn "Done..."
Console.ReadLine() |> ignore