Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

XML Parser

New Here ,
Aug 28, 2014 Aug 28, 2014

Hi,

i use CF to parse an XML FILE, i'm stucking now with this part:

<HR.PUB.CONTENT>

<FT TYPE="F">Example GmbH</FT>

, now in Zurich,

<FT TYPE="A">CHE-100.000.000</FT>

, City new:

<FT TYPE="S">Erlenbach ZH</FT>

. Address new: Haldenstrasse, 8700 Erlenbach ZH.

</HR.PUB.CONTENT>


I just want one string like that:

Example GmbH, now in Zurich, CHE-100.000.000, city news: Erlenbach ZH. Address new: Haldenstrasse, 8700 Erlenbach ZH.


i tried this one, but it wasn't useful:

Text= xmlsearch(MyData, "//HR01/HR01.SPEC/HR.PUB.CONTENT")[idxAttr1].XmlText



Can anyone help me? I use <cfscript>



183
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2014 Aug 29, 2014
LATEST

XML is quite suited to the text of the FT elements. But not for the inline text, now in Zurich, City new:, etc.


You could do it in 2 parts. String parsing (as list) for the inline text, and XML parsing (as associative array) for the XmlText.

<cfset str = "">

<!--- string --->

<cfsavecontent variable="strDoc"><HR.PUB.CONTENT>

<FT TYPE="F">Example GmbH</FT>

, now in Zurich,

<FT TYPE="A">CHE-100.000.000</FT>

, City new:

<FT TYPE="S">Erlenbach ZH</FT>

. Address new: Haldenstrasse, 8700 Erlenbach ZH.

</HR.PUB.CONTENT></cfsavecontent>

<!--- xml --->

<cfxml variable="xmlDoc"><cfoutput>#strDoc#</cfoutput></cfxml>

<!--- Pick out the Xmltext --->

<cfset elemText = arrayNew(1)>

<cfset n = 1>

<cfloop array="#xmldoc['HR.PUB.CONTENT'].xmlChildren#" index="FT_elem">

<cfset elemText = FT_elem.XmlText>

<cfif n LT arrayLen(xmldoc['HR.PUB.CONTENT'].xmlChildren)>

<cfset n++>

</cfif>

</cfloop>

<!--- In the string, replace the FT elements and their contents with the delimiter "|", creating a suitable list --->

<cfset inlineText = REreplace(strDoc,"<FT\b[^>]*>(.*?)</FT>","|","all")>

<!--- Take an entry from the array and the next immediate entry from the list --->

<cfloop from="1" to="#n#" index="idx">

<cfset str = str & elemText[idx] & listGetAt(inlineText,idx+1,'|') >

</cfloop>

<cfoutput>#str#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources