I am doing xml export, when there is & in any of my field it throws error, and it shows as white space not allowed in the xml file. Does any one know how to handle this.
I am trying to search this information, I could understand that you can use CDATA, by using this CDATA, that particular field will not be converted in xml format and it will just take the data as it is, and the error doesn’t come up.
But I am not getting help anywhere how to write the code for this.
I am doing this in notes client using lotus script. Please help me if any one knows about this. Thanks.
Subject: handling special characters -while xml exprot from lotus notes
print “”
Subject: RE: handling special characters -while xml exprot from lotus notes
Thanks for your response, I am trying to write your code as below, but still there is no difference. could you please send me the exact code.
Case DOMNODETYPE_CDATASECTION_NODE: 'It’s a CDATA section
if a.nodename=“age” then
Print “”
end if
Please help me. Thanks
Subject: RE: handling special characters -while xml exprot from lotus notes
Would you please post your code, and I’ll try to help debug it. a.nodename is not a field value. I need to see:
-
what data you’re starting with (samples, please)
-
what the code is
-
and what the desired output is
4 what the actual output of your code is
Also, in what context are you running this. Against notes docs in a view using a webquerysave agent, etc.?
Subject: RE: handling special characters -while xml exprot from lotus notes
I am trying to run schedule agent from notes client not browser. The problem I am facing is, while exporting into xml, if in the notes field if there is “&” which is the special character, then the xml file is getting truncated. May be we can use replace this substring, but there is also another field in which the user uses tab, by which in the xml document , %break is appearing . I have read somewhere that I can use CDATA, which will take the data as it is to the xml and it won’t convet by which it will not throw error, or if you know any alternative solution you can suggest. Thank you very much for your response.
And my code is
Sub walkTree1 ( node As NotesDOMNode)
Dim child As NotesDOMNode
Dim attrs As NotesDOMNamedNodeMap
Dim a As NotesDOMAttributeNode
Dim piNode As NotesDOMProcessingInstructionNode
LF = Chr(13)+Chr(10)
If Not node.IsNull Then
Select Case node.NodeType
Case DOMNODETYPE_DOCUMENT_NODE: 'It's the Document node
Set child = node.FirstChild 'Get first node
Dim numChildNodes As Integer
numChildNodes = node.NumberOfChildNodes
'Create an XML declaration for the output
Dim xNode As NotesDOMXMLDeclNode
Set xNode = node.FirstChild
domParser.Output({<?xml version="} + xNode.Version + {" ?>})
'Get the number of children of Document, and call walkTree for the first child
While numChildNodes > 0
Set child = child.NextSibling 'Get next node
numChildNodes = numChildNodes - 1
Call walkTree1(child)
Wend
Case DOMNODETYPE_DOCUMENTTYPE_NODE: 'It's a <!DOCTYPE> tag
domParser.Output({Document Type node: } + node.NodeName + LF)
Case DOMNODETYPE_TEXT_NODE: 'It's a plain text node
If node.NodeValue <> Chr(10) Then
domParser.Output(node.NodeValue)
End If
Case DOMNODETYPE_ELEMENT_NODE: 'Most nodes are Element nodes
If node.NodeName = "databaseinfo" Then
Exit Sub
End If
If node.NodeName = "noteinfo" Then
Exit Sub
End If
If node.NodeName = "updatedby" Then
Exit Sub
End If
domParser.Output({<} + node.NodeName)
Dim numAttributes As Integer, numChildren As Integer
numAttributes = node.attributes.numberofentries
Set attrs = node.Attributes 'Get attributes
Dim i As Integer
For i = 1 To numAttributes 'Loop through attributes
Set a = attrs.GetItem(i)
domParser.Output({ }+a.NodeName + {="} + a.NodeValue + {"})
Next
domParser.Output(">")
numChildren = node.NumberOfChildNodes
Set child = node.FirstChild 'Get child
While numChildren > 0
Call walkTree1(child)
Set child = child.NextSibling 'Get next child
numChildren = numChildren - 1
Wend
domParser.Output( {</} + node.nodeName + {>} + LF)
Case DOMNODETYPE_COMMENT_NODE: 'It's a Comment
'domParser.Output({Ignoring node: } + Cstr(node.NodeType) + LF)
Case DOMNODETYPE_PROCESSINGINSTRUCTION_NODE: 'It's a PI node
'domParser.Output({Ignoring node: } + Cstr(node.NodeType) + LF)
Case DOMNODETYPE_CDATASECTION_NODE: 'It's a CDATA section
'domParser.Output({Ignoring node: } + Cstr(node.NodeType) + LF)
Case DOMNODETYPE_ENTITYREFERENCE_NODE: 'It's an entity
'domParser.Output({Ignoring node: } + Cstr(node.NodeType) + LF)
Case Else:
'domParser.Output({Ignoring node: } + Cstr(node.NodeType) + LF)
End Select
End If
End Sub
Subject: RE: handling special characters -while xml exprot from lotus notes
You aren’t going to find the “bad” characters in CDATA section nodes – if that’s where they lived, there’d be no need to do anything. You’ll find them in text nodes, which you need to convert to CDATA. That, however, isn’t necessarily the best approach. If the data is in a text node, why not simply replace the ampersand with & and any less-than or greater-than characters with < and > respectively.
Subject: RE: handling special characters -while xml exprot from lotus notes
I’m in agreement with Stan.
That said, if you are starting with XML and are outputting XML, then you should probably consider coding XSLT to handle this and calling a transform function. I think it will be cleaner and easier.