Last active
June 10, 2019 10:37
-
-
Save henryhamon/84ed1e7f0c0d3ac781b1f4090aea9d52 to your computer and use it in GitHub Desktop.
CorrelateXML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class utl.Xml | |
{ | |
ClassMethod CorrelateStream(pXMLStream As %CharacterStream, pClasse As %String, pTag As %String, Output pObjXML As %XML.Adaptor) As %Status | |
{ | |
Set tSC = $$$OK | |
Try | |
{ | |
Set tXMLReader = ##class(%XML.Reader).%New() | |
Set tSC = tXMLReader.OpenStream(pXMLStream) | |
Throw:$$$ISERR(tSC) | |
Do tXMLReader.Correlate(pTag,pClasse) | |
Set tRNext = tXMLReader.Next(.pObjXML,.tSC) | |
Throw:$$$ISERR(tSC) | |
If ($IsObject(pObjXML)'=1) | |
{ | |
Set tDescErro = "Objeto não correlacionado; Verificar Schema: "_pClasse_ $Select(pXMLStream.%IsA("%FileBinaryStream"):" ArquivoXML: "_pXMLStream.Filename,1:"") | |
Set tSC=$System.Status.Error(5001,tDescErro_$system.Status.GetErrorText(tSC)) | |
Throw | |
} | |
} | |
Catch tException | |
{ | |
Set:'$$$ISERR(tSC) tSC=tException.AsStatus() | |
Set tDescErro= $system.Status.GetErrorText(tSC) | |
$$$TRACE(tDescErro) | |
Set tSC=$System.Status.Error(5001,"Erro na estrutura do XML | "_tDescErro) | |
} | |
Quit tSC | |
} | |
ClassMethod ConverterObjetoXML(pObjeto As vo.xml, Output pOutput As %CharacterStream) | |
{ | |
Set tSC = $$$OK | |
Try | |
{ | |
Set tEscritorXML = ##class(%XML.Writer).%New() | |
Set tEscritorXML.Charset ="UTF-8" | |
Set tSC = tEscritorXML.OutputToStream(.pOutput) | |
Throw:$$$ISERR(tSC) | |
Set tSC = tEscritorXML.RootObject(pObjeto) | |
Throw:$$$ISERR(tSC) | |
} | |
Catch tException | |
{ | |
Set:'$$$ISERR(tSC) tSC=tException.AsStatus() | |
} | |
Quit tSC | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment