使用 NSXMLParser 和 Swift 解析 SOAP 响应

使用 NSXMLParser 和 Swift 解析 SOAP 响应

问题描述:

我正在尝试使用 NSXMLParser 解析 Soap 响应(如下所示的代码段).但是,当我在 didStartElemnt 委托方法中打印元素名称时,我只会返回以下元素.

I am trying to parse the Soap response (snippet shown below) using NSXMLParser. However when I print the Element names in the didStartElemnt delegate method I only get the following elements returned.

元素的名称是soap:Envelope

Element's name is soap:Envelope

元素的名称是soap:Body

Element's name is soap:Body

元素的名称是 SearchResponse

Element's name is SearchResponse

元素的名称是 SearchResult

Element's name is SearchResult

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<SearchResponse xmlns="http://www.example.com/">
			<SearchResult><?xml version="1.0" encoding="utf-8"?><Results xmlns="http://www.example.com/XMLSchema/SearchResult" xmlns:gms="http://www.def.ghi.uk/CM/gms" xmlns:n2=" (more here + further elements....)

为什么我看不到结果(或任何后续)元素?

Why do I not see the Results (or any subsequent) element?

很可能是第二个 <?xml ...> 指令出现在 中.该指令仅允许在 xml 文件的开头使用.

Most likely it's the second <?xml . . .> directive that appears inside the <SearchResult>. That directive is only allowed at the start of an xml file.