I am looking for the solution to the following problem
Either the following XML string
<AdrTp> </AdrTp>
<Name> </Name>
When I create the xml file I get the following result
<AddrTp/>
<Name/>
But I absolutely need the following exit
<AdrTp></AdrTp>
<Name></Name>
Is it possible to get this result in XML creation or if not how can I solve the problem with a regular expression (I couldn't find the right expression so if someone had it it would be nice to pass it to me)
Thank you in advance
Regular expression help Or XML Help
-
- Enthusiast
- Posts: 501
- Joined: Tue Oct 14, 2014 12:09 pm
Re: Regular expression help Or XML Help
Something like this:
Code: Select all
EnableExplicit
Procedure.s ReplaceSeflClosingXmlTags(xmlString.s)
Static r
If Not r
r = CreateRegularExpression(#PB_Any, "<([^ >]+)([^>]*)/>")
If Not r : ProcedureReturn #Empty$ : EndIf
EndIf
While ExamineRegularExpression(r, xmlString)
If NextRegularExpressionMatch(r)
xmlString = Left(xmlString, RegularExpressionMatchPosition(r)-1) +
"<" + RegularExpressionGroup(r, 1) + RegularExpressionGroup(r, 2) + ">" +
"</" + RegularExpressionGroup(r, 1) + ">" +
Right(xmlString, Len(xmlString) - RegularExpressionMatchLength(r) - RegularExpressionMatchPosition(r) +1)
Else
Break
EndIf
Wend
ProcedureReturn xmlString
EndProcedure
Define xml
Define nMain
Define nAdrTpl
Define nName
Define sXML1.s
Define sXML2.s
xml = CreateXML(#PB_Any)
nMain = CreateXMLNode(RootXMLNode(xml), "Main")
nAdrTpl = CreateXMLNode(nMain, "AdrTpl")
nName = CreateXMLNode(nMain, "Name")
sXML1 = ComposeXML(xml)
sXML2 = ReplaceSeflClosingXmlTags(sXML1)
Debug sXML1
Debug "----------"
Debug sXML2
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
Re: Regular expression help Or XML Help
This one should be more effective, if there are repetitions of self-closing tags:
Code: Select all
Procedure.s ReplaceSeflClosingXmlTags(xmlString.s)
Static r
Protected search.s, replace.s
If Not r
r = CreateRegularExpression(#PB_Any, "<([^ >]+)([^>]*)/>")
If Not r : ProcedureReturn #Empty$ : EndIf
EndIf
While ExamineRegularExpression(r, xmlString)
If NextRegularExpressionMatch(r)
search = RegularExpressionMatchString(r)
replace = "<" + RegularExpressionGroup(r, 1) + RegularExpressionGroup(r, 2) + ">" +
"</" + RegularExpressionGroup(r, 1) + ">"
xmlString = ReplaceString(xmlString, search, replace)
Else
Break
EndIf
Wend
ProcedureReturn xmlString
EndProcedure
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
Re: Regular expression help Or XML Help
My version without additional libraries:
Code: Select all
xml = CreateXML(#PB_Any)
nMain = CreateXMLNode(RootXMLNode(xml), "Main")
nAdrTpl = CreateXMLNode(nMain, "AdrTpl")
SetXMLNodeText(nAdrTpl, " ")
nName = CreateXMLNode(nMain, "Name")
SetXMLNodeText(nName, " ")
XML$ = ComposeXML(xml)
xml$ = ReplaceString(XML$, "> <", "><")
Debug XML$
Re: Regular expression help Or XML Help
This only works if your application does not need to handle slingle spaces as node text!infratec wrote:My version without additional libraries:
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
Re: Regular expression help Or XML Help
Ok, so replace > < by >jqzwguqfguqwezgfuz<
I think thats secure enough
I think thats secure enough
Re: Regular expression help Or XML Help
Special version for helpy:
Code: Select all
#DummyRemovalText$ = "xyz123-321zxy"
xml = CreateXML(#PB_Any)
nMain = CreateXMLNode(RootXMLNode(xml), "Main")
nAdrTpl = CreateXMLNode(nMain, "AdrTpl")
SetXMLNodeText(nAdrTpl, #DummyRemovalText$)
nName = CreateXMLNode(nMain, "Name")
SetXMLNodeText(nName, #DummyRemovalText$)
XML$ = ComposeXML(xml)
xml$ = ReplaceString(XML$, ">" + #DummyRemovalText$ + "<", "><")
Debug XML$
Re: Regular expression help Or XML Help
TOP :thumbs-up:
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing