LeadCo
asked on
Parse xml With coldfusion I beleive I am close
Hello Experts The code in the code window is the script i am using to parse the xml however it s not working. i think its close but I am no expert!
<?xml version="1.0" encoding="utf-8"?><soap:En velope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><G etQuotesRe sponse xmlns="http://www.awebsite.net"><GetQuotesResult> <ErrorMsg /><Valid>true</Valid><Quot es><FaceAm ountQuote> <Quote><Qu oteValues> <FaceValue >100000</F aceValue>< ClientPrem ium>91.66< /ClientPre mium><Fami lyPremium> 99.36</Fam ilyPremium ></QuoteVa lues><Quot eValues><F aceValue>9 0000</Face Value><Cli entPremium >82.66</Cl ientPremiu m><FamilyP remium>90. 36</Family Premium></ QuoteValue s><QuoteVa lues><Face Value>8000 0</FaceVal ue><Client Premium>73 .66</Clien tPremium>< FamilyPrem ium>81.36< /FamilyPre mium></Quo teValues>< QuoteValue s><FaceVal ue>70000</ FaceValue> <ClientPre mium>64.66 </ClientPr emium><Fam ilyPremium >72.36</Fa milyPremiu m></QuoteV alues><Quo teValues>< FaceValue> 60000</Fac eValue><Cl ientPremiu m>55.66</C lientPremi um><Family Premium>63 .36</Famil yPremium>< /QuoteValu es><QuoteV alues><Fac eValue>500 00</FaceVa lue><Clien tPremium>4 6.66</Clie ntPremium> <FamilyPre mium>54.36 </FamilyPr emium></Qu oteValues> <QuoteValu es><FaceVa lue>40000< /FaceValue ><ClientPr emium>37.6 6</ClientP remium><Fa milyPremiu m>45.36</F amilyPremi um></Quote Values><Qu oteValues> <FaceValue >30000</Fa ceValue><C lientPremi um>28.66</ ClientPrem ium><Famil yPremium>3 6.36</Fami lyPremium> </QuoteVal ues></Quot e></FaceAm ountQuote> <MoneyPurc haseQuote> <Quote><Qu oteValues> <FaceValue >98156</Fa ceValue><C lientPremi um>90</Cli entPremium ><FamilyPr emium>97.7 </FamilyPr emium></Qu oteValues> <QuoteValu es><FaceVa lue>92600< /FaceValue ><ClientPr emium>85</ ClientPrem ium><Famil yPremium>9 2.7</Famil yPremium>< /QuoteValu es><QuoteV alues><Fac eValue>870 44</FaceVa lue><Clien tPremium>8 0</ClientP remium><Fa milyPremiu m>87.7</Fa milyPremiu m></QuoteV alues><Quo teValues>< FaceValue> 81489</Fac eValue><Cl ientPremiu m>75</Clie ntPremium> <FamilyPre mium>82.7< /FamilyPre mium></Quo teValues>< QuoteValue s><FaceVal ue>75933</ FaceValue> <ClientPre mium>70</C lientPremi um><Family Premium>77 .7</Family Premium></ QuoteValue s><QuoteVa lues><Face Value>7037 8</FaceVal ue><Client Premium>65 </ClientPr emium><Fam ilyPremium >72.7</Fam ilyPremium ></QuoteVa lues><Quot eValues><F aceValue>6 4822</Face Value><Cli entPremium >60</Clien tPremium>< FamilyPrem ium>67.7</ FamilyPrem ium></Quot eValues><Q uoteValues ><FaceValu e>59267</F aceValue>< ClientPrem ium>55</Cl ientPremiu m><FamilyP remium>62. 7</FamilyP remium></Q uoteValues ><QuoteVal ues><FaceV alue>53711 </FaceValu e><ClientP remium>50< /ClientPre mium><Fami lyPremium> 57.7</Fami lyPremium> </QuoteVal ues><Quote Values><Fa ceValue>48 156</FaceV alue><Clie ntPremium> 45</Client Premium><F amilyPremi um>52.7</F amilyPremi um></Quote Values><Qu oteValues> <FaceValue >42600</Fa ceValue><C lientPremi um>40</Cli entPremium ><FamilyPr emium>47.7 </FamilyPr emium></Qu oteValues> <QuoteValu es><FaceVa lue>37044< /FaceValue ><ClientPr emium>35</ ClientPrem ium><Famil yPremium>4 2.7</Famil yPremium>< /QuoteValu es><QuoteV alues><Fac eValue>314 89</FaceVa lue><Clien tPremium>3 0</ClientP remium><Fa milyPremiu m>37.7</Fa milyPremiu m></QuoteV alues><Quo teValues>< FaceValue> 25933</Fac eValue><Cl ientPremiu m>25</Clie ntPremium> <FamilyPre mium>32.7< /FamilyPre mium></Quo teValues>< QuoteValue s><FaceVal ue>20378</ FaceValue> <ClientPre mium>20</C lientPremi um><Family Premium>27 .7</Family Premium></ QuoteValue s></Quote> </MoneyPur chaseQuote ></Quotes> <SpouseFac e>10000</S pouseFace> <ChildrenF ace>0</Chi ldrenFace> <BenefitDe scription> &lt;p& amp;gt;A Ten-Year renewable and convertible term life insurance policy with critical condition accelerated benefit rider.&nbsp;&lt;/p &gt;&a mp;lt;p&am p;gt;LifeS tyle Protector will pay as a lump sum, the percentage of your term life insurance benefit if you are first diagnosed with one of the following:&lt;/p&g t;&lt; ul&gt; &lt;li &gt;Ca ncer (Life Threatening) 100%&lt;/li&gt;&am p;lt;li&am p;gt;Heart Attack 100%&lt;/li&gt;&am p;lt;li&am p;gt;Strok e 100%&lt;/li&gt;&am p;lt;li&am p;gt;Renal Failure 100%&lt;/li&gt;&am p;lt;li&am p;gt;Major Organ Transplant 100%&lt;/li&gt;&am p;lt;li&am p;gt;Termi nal Illness 100%&lt;/li&gt;&am p;lt;li&am p;gt;Total Disability* (Sickness or Accident) 100%&lt;/li&gt;&am p;lt;li&am p;gt;Major Heart Surgery 25%&lt;/li&gt;& ;lt;li& ;gt;HIV From a Blood Transfusion 25%&lt;/li&gt;& ;lt;li& ;gt;Angiop lasty 10%&lt;/li&gt;& ;lt;/ul&am p;gt;& lt;p&g t;Death from any cause is a 100% benefit.&lt;/p&gt; &lt;p& amp;gt;(&a mp;lt;i&am p;gt;Excep t suicide during the first two years&lt;/i&gt;.)& amp;lt;/p& amp;gt;&am p;lt;p& ;gt;Pays in addition to any other insurance you have!&lt;/p&gt;&am p;lt;p& ;gt;* 10% of the policy face amount every 5 years if you receive Social Security Disability Benefits, and the remaining 50% of the policy face amount at the end of 5 years if you are still receiving Social Security Disability Benefits for a total pay of 100%.&lt;/p&gt;&am p;lt;p& ;gt;Same exclusion and exceptions apply. Benefits may differ or not be available in some states. Your agent will explain the benefits available in your state.&lt;/p&gt;</ BenefitDes cription>< QRequest>< RequestTra nsactionID >1411</Req uestTransa ctionID><R equestStat e>AL</Requ estState>< RequestCli entAge>38< /RequestCl ientAge><R equestClie ntTobacco> false</Req uestClient Tobacco><R equestSpou seAge>38</ RequestSpo useAge><Re questSpous eTobacco>f alse</Requ estSpouseT obacco><Re questModal >Monthly</ RequestMod al><Reques tFamilySta tus>Spouse Only</Requ estFamilyS tatus></QR equest></G etQuotesRe sult></Get QuotesResp onse></soa p:Body></s oap:Envelo pe>
<?xml version="1.0" encoding="utf-8"?><soap:En
<--- Code i am using I think its close just no cigar --->
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(XMLContent, "/GetQuotesResponse/GetQuotesResult/ErrorMsg/Valid");
</cfscript>
<cfset Face1 = #xmlNode[1].Quotes.FaceAmountQuote.Quote.QuoteValues.FaceValue.xmltext#>
<cfset prem1 = #xmlNode[1].Quotes.FaceAmountQuote.Quote.QuoteValues.ClientPremium.xmltext#>
<cfset Fpremium1 = #xmlNode[1].Quotes.FaceAmountQuote.Quote.QuoteValues.FamilyPremium.xmltext#>
<cfoutput>
Face= #face1# Prem= #prem1# Family prem = #fpremium1#
</cfoutput>
I am not a coldfusion expert, but I do note two things that definitely need tweaking before you get the code working:
- the second argument of xmlSearch takes an xpath. You start the xpath with a "/", which means the the search will start at the root node. You need to give it a the full path starting from the root, or use "//" (which means "anywhere" in the document and should only be used if you do not know where the element is).
- (this is more important) you use a namespace in the xml SOAP document. This is a good thing, but xmlSearch cannot deal with namespaces, here's a quote from xmlSearch documentation: XMLSearch() works fine until you set a XmlNsURI anywhere in the XML document. You can test this by adding a xmlns="anyURLHere" name attribute in any tag in your XML file. Once this is set, XMLSearch() breaks.
Apparently, ColdFusion is not namespace aware, or at least only partially. That's a pity and a large miss, but rest assured, there are a couple of solutions. One of the solutions I already touched at in my first reply is explained here: http://www.aftergeek.com/2006/08/xmlsearch-xpath-and-xml-namespaces-in.html (making the xpath namespace agnostic).
Here's the copy and paste solution, but quite unreadable (like I predicted). This is not the fault of XPath or XML, but the problem with ColdFusion:
*[local-name() = 'Envelope']/ *[local-name() = 'Body']/ *[local-name() = 'GetQuotesResponse']/ *[local-name() = 'GetQuotesResult']/ *[local-name() = 'ErrorMsg']/ following-sibling::*[local -name() = 'Valid']
This is a the same as this in "real" XPath when the namespaces would be set correctly:
soap:Envelope/ soap:Body/ GetQuotesResponse/ GetQuotesResult/ ErrorMsg/ following-sibling::Valid
note the difference compared to your original statement where you wrote down "Valid" as a child of "ErrorMsg", but in fact, it is on the same level, which is done with "following-sibling::" at the end.
Finally, I'd like you to try one of the following statements (either/or), which is not valid XPath, but according to different posts on ColdFusion is allowed with XmlSearch:
*:Envelope/ *:Body/ *:GetQuotesResponse/ *:GetQuotesResult/ *:ErrorMsg/ following-sibling::*:Valid
or:
:Envelope/ :Body/ :GetQuotesResponse/ :GetQuotesResult/ :ErrorMsg/ following-sibling:::Valid
(that last one seems strange as it would force you to use ":::" in conjunction with following-sibling, but these weird things happen if language makers diverge from the specifications)
Here's the copy and paste solution, but quite unreadable (like I predicted). This is not the fault of XPath or XML, but the problem with ColdFusion:
*[local-name() = 'Envelope']/ *[local-name() = 'Body']/ *[local-name() = 'GetQuotesResponse']/ *[local-name() = 'GetQuotesResult']/ *[local-name() = 'ErrorMsg']/ following-sibling::*[local
This is a the same as this in "real" XPath when the namespaces would be set correctly:
soap:Envelope/ soap:Body/ GetQuotesResponse/ GetQuotesResult/ ErrorMsg/ following-sibling::Valid
note the difference compared to your original statement where you wrote down "Valid" as a child of "ErrorMsg", but in fact, it is on the same level, which is done with "following-sibling::" at the end.
Finally, I'd like you to try one of the following statements (either/or), which is not valid XPath, but according to different posts on ColdFusion is allowed with XmlSearch:
*:Envelope/ *:Body/ *:GetQuotesResponse/ *:GetQuotesResult/ *:ErrorMsg/ following-sibling::*:Valid
or:
:Envelope/ :Body/ :GetQuotesResponse/ :GetQuotesResult/ :ErrorMsg/ following-sibling:::Valid
(that last one seems strange as it would force you to use ":::" in conjunction with following-sibling, but these weird things happen if language makers diverge from the specifications)
Btw, it works much easier if you indent your XML. It's easier for us to read and easier for yourself to understand. Indenting XML is hardly ever a problem with the content as most whitespace is ignorable.
ASKER
Commented XML :
<?xml version="1.0" encoding="utf-8"?><soap:En velope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>
<GetQuotesResponse xmlns="http://www.awebsite.net">
<GetQuotesResult>
<ErrorMsg />
<Valid>true</Valid>
<Quotes>
<FaceAmountQuote>
<Quote>
<QuoteValues>
<FaceValue>100000</FaceVal ue>
<ClientPremium>91.66</Clie ntPremium>
<FamilyPremium>99.36</Fami lyPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>90000</FaceValu e>
<ClientPremium>82.66</Clie ntPremium>
<FamilyPremium>90.36</Fami lyPremium>
</QuoteValues><QuoteValues >
<FaceValue>80000</FaceValu e>
<ClientPremium>73.66</Clie ntPremium>
<FamilyPremium>81.36</Fami lyPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>70000</FaceValu e>
<ClientPremium>64.66</Clie ntPremium>
<FamilyPremium>72.36</Fami lyPremium>
</QuoteValues><QuoteValues >
<FaceValue>60000</FaceValu e>
<ClientPremium>55.66</Clie ntPremium>
<FamilyPremium>63.36</Fami lyPremium> </QuoteVal ues>
<QuoteValues>
<FaceValue>50000</FaceValu e>
<ClientPremium>46.66</Clie ntPremium>
<FamilyPremium>54.36</Fami lyPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>40000</FaceValu e>
<ClientPremium>37.66</Clie ntPremium>
<FamilyPremium>45.36</Fami lyPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>30000</FaceValu e>
<ClientPremium>28.66</Clie ntPremium>
<FamilyPremium>36.36</Fami lyPremium>
</QuoteValues>
</Quote>
</FaceAmountQuote>
<MoneyPurchaseQuote>
<Quote>
<QuoteValues>
<FaceValue>98156</FaceValu e>
<ClientPremium>90</ClientP remium>
<FamilyPremium>97.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>92600</FaceValu e>
<ClientPremium>85</ClientP remium>
<FamilyPremium>92.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>87044</FaceValu e>
<ClientPremium>80</ClientP remium>
<FamilyPremium>87.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>81489</FaceValu e>
<ClientPremium>75</ClientP remium>
<FamilyPremium>82.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>75933</FaceValu e>
<ClientPremium>70</ClientP remium>
<FamilyPremium>77.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>70378</FaceValu e>
<ClientPremium>65</ClientP remium>
<FamilyPremium>72.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>64822</FaceValu e>
<ClientPremium>60</ClientP remium>
<FamilyPremium>67.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>59267</FaceValu e>
<ClientPremium>55</ClientP remium>
<FamilyPremium>62.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>53711</FaceValu e>
<ClientPremium>50</ClientP remium>
<FamilyPremium>57.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>48156</FaceValu e>
<ClientPremium>45</ClientP remium>
<FamilyPremium>52.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>42600</FaceValu e>
<ClientPremium>40</ClientP remium>
<FamilyPremium>47.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>37044</FaceValu e>
<ClientPremium>35</ClientP remium>
<FamilyPremium>42.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>31489</FaceValu e>
<ClientPremium>30</ClientP remium>
<FamilyPremium>37.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>25933</FaceValu e>
<ClientPremium>25</ClientP remium>
<FamilyPremium>32.7</Famil yPremium>
</QuoteValues>
<QuoteValues>
<FaceValue>20378</FaceValu e>
<ClientPremium>20</ClientP remium>
<FamilyPremium>27.7</Famil yPremium>
</QuoteValues>
</Quote>
</MoneyPurchaseQuote></Quo tes>
<SpouseFace>10000</SpouseF ace>
<ChildrenFace>0</ChildrenF ace>
<BenefitDescription>&l t;p&gt ;A Ten-Year renewable and convertible term life insurance policy with critical condition accelerated benefit rider.&nbsp;&lt;/p &gt;&a mp;lt;p&am p;gt;LifeS tyle Protector will pay as a lump sum, the percentage of your term life insurance benefit if you are first diagnosed with one of the following:&lt;/p&g t;&lt; ul&gt; &lt;li &gt;Ca ncer (Life Threatening) 100%&lt;/li&gt;&am p;lt;li&am p;gt;Heart Attack 100%&lt;/li&gt;&am p;lt;li&am p;gt;Strok e 100%&lt;/li&gt;&am p;lt;li&am p;gt;Renal Failure 100%&lt;/li&gt;&am p;lt;li&am p;gt;Major Organ Transplant 100%&lt;/li&gt;&am p;lt;li&am p;gt;Termi nal Illness 100%&lt;/li&gt;&am p;lt;li&am p;gt;Total Disability* (Sickness or Accident) 100%&lt;/li&gt;&am p;lt;li&am p;gt;Major Heart Surgery 25%&lt;/li&gt;& ;lt;li& ;gt;HIV From a Blood Transfusion 25%&lt;/li&gt;& ;lt;li& ;gt;Angiop lasty 10%&lt;/li&gt;& ;lt;/ul&am p;gt;& lt;p&g t;Death from any cause is a 100% benefit.&lt;/p&gt; &lt;p& amp;gt;(&a mp;lt;i&am p;gt;Excep t suicide during the first two years&lt;/i&gt;.)& amp;lt;/p& amp;gt;&am p;lt;p& ;gt;Pays in addition to any other insurance you have!&lt;/p&gt;&am p;lt;p& ;gt;* 10% of the policy face amount every 5 years if you receive Social Security Disability Benefits, and the remaining 50% of the policy face amount at the end of 5 years if you are still receiving Social Security Disability Benefits for a total pay of 100%.&lt;/p&gt;&am p;lt;p& ;gt;Same exclusion and exceptions apply. Benefits may differ or not be available in some states. Your agent will explain the benefits available in your state.&lt;/p&gt;</ BenefitDes cription>
<QRequest>
<RequestTransactionID>1411 </RequestT ransaction ID>
<RequestState>AL</RequestS tate>
<RequestClientAge>38</Requ estClientA ge>
<RequestClientTobacco>fals e</Request ClientToba cco>
<RequestSpouseAge>38</Requ estSpouseA ge>
<RequestSpouseTobacco>fals e</Request SpouseToba cco>
<RequestModal>Monthly</Req uestModal>
<RequestFamilyStatus>Spous eOnly</Req uestFamily Status>
</QRequest>
</GetQuotesResult>
</GetQuotesResponse>
</soap:Body>
</soap:Envelope>
<?xml version="1.0" encoding="utf-8"?><soap:En
<GetQuotesResponse xmlns="http://www.awebsite.net">
<GetQuotesResult>
<ErrorMsg />
<Valid>true</Valid>
<Quotes>
<FaceAmountQuote>
<Quote>
<QuoteValues>
<FaceValue>100000</FaceVal
<ClientPremium>91.66</Clie
<FamilyPremium>99.36</Fami
</QuoteValues>
<QuoteValues>
<FaceValue>90000</FaceValu
<ClientPremium>82.66</Clie
<FamilyPremium>90.36</Fami
</QuoteValues><QuoteValues
<FaceValue>80000</FaceValu
<ClientPremium>73.66</Clie
<FamilyPremium>81.36</Fami
</QuoteValues>
<QuoteValues>
<FaceValue>70000</FaceValu
<ClientPremium>64.66</Clie
<FamilyPremium>72.36</Fami
</QuoteValues><QuoteValues
<FaceValue>60000</FaceValu
<ClientPremium>55.66</Clie
<FamilyPremium>63.36</Fami
<QuoteValues>
<FaceValue>50000</FaceValu
<ClientPremium>46.66</Clie
<FamilyPremium>54.36</Fami
</QuoteValues>
<QuoteValues>
<FaceValue>40000</FaceValu
<ClientPremium>37.66</Clie
<FamilyPremium>45.36</Fami
</QuoteValues>
<QuoteValues>
<FaceValue>30000</FaceValu
<ClientPremium>28.66</Clie
<FamilyPremium>36.36</Fami
</QuoteValues>
</Quote>
</FaceAmountQuote>
<MoneyPurchaseQuote>
<Quote>
<QuoteValues>
<FaceValue>98156</FaceValu
<ClientPremium>90</ClientP
<FamilyPremium>97.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>92600</FaceValu
<ClientPremium>85</ClientP
<FamilyPremium>92.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>87044</FaceValu
<ClientPremium>80</ClientP
<FamilyPremium>87.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>81489</FaceValu
<ClientPremium>75</ClientP
<FamilyPremium>82.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>75933</FaceValu
<ClientPremium>70</ClientP
<FamilyPremium>77.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>70378</FaceValu
<ClientPremium>65</ClientP
<FamilyPremium>72.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>64822</FaceValu
<ClientPremium>60</ClientP
<FamilyPremium>67.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>59267</FaceValu
<ClientPremium>55</ClientP
<FamilyPremium>62.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>53711</FaceValu
<ClientPremium>50</ClientP
<FamilyPremium>57.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>48156</FaceValu
<ClientPremium>45</ClientP
<FamilyPremium>52.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>42600</FaceValu
<ClientPremium>40</ClientP
<FamilyPremium>47.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>37044</FaceValu
<ClientPremium>35</ClientP
<FamilyPremium>42.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>31489</FaceValu
<ClientPremium>30</ClientP
<FamilyPremium>37.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>25933</FaceValu
<ClientPremium>25</ClientP
<FamilyPremium>32.7</Famil
</QuoteValues>
<QuoteValues>
<FaceValue>20378</FaceValu
<ClientPremium>20</ClientP
<FamilyPremium>27.7</Famil
</QuoteValues>
</Quote>
</MoneyPurchaseQuote></Quo
<SpouseFace>10000</SpouseF
<ChildrenFace>0</ChildrenF
<BenefitDescription>&l
<QRequest>
<RequestTransactionID>1411
<RequestState>AL</RequestS
<RequestClientAge>38</Requ
<RequestClientTobacco>fals
<RequestSpouseAge>38</Requ
<RequestSpouseTobacco>fals
<RequestModal>Monthly</Req
<RequestFamilyStatus>Spous
</QRequest>
</GetQuotesResult>
</GetQuotesResponse>
</soap:Body>
</soap:Envelope>
ASKER
abel: I tried to try that way in several ways. It would not let me use * or : in cfscript.
I tried:
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent,
*:Envelope/
*:Body/
*:GetQuotesResponse/
*:GetQuotesResult/
*:ErrorMsg/
following-sibling::*:Valid
</cfscript>
I get this:
Missing argument name.
When using named parameters to a function, every parameter must have a name.
I tried:
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent,
*:Envelope/
*:Body/
*:GetQuotesResponse/
*:GetQuotesResult/
*:ErrorMsg/
following-sibling::*:Valid
</cfscript>
I get this:
Missing argument name.
When using named parameters to a function, every parameter must have a name.
ASKER
With this i get:
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent,
:Envelope/
:Body/
:GetQuotesResponse/
:GetQuotesResult/
:ErrorMsg/
following-sibling:::Valid
</cfscript>
When using named parameters to a function, every parameter must have a name.
The CFML compiler was processing:
An expression beginning with xmlSearch, on line 63, column 13.This message is usually caused by a problem in the expressions structure.
A script statement beginning with xmlNode on line 63, column 3.
A cfscript tag beginning on line 60, column 2.
Thanks for trying.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My code looks like this:
<!---Version 3 --->
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, "*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'GetQuotesResponse']/*[loc al-name() = 'GetQuotesResult']/*[local -name() = 'ErrorMsg']/following-sibl ing::*[loc al-name() = 'Valid']");
</cfscript>
An error occured while Parsing an XML document.
Premature end of file.
<!---Version 3 --->
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, "*[local-name() = 'Envelope']/*[local-name()
</cfscript>
An error occured while Parsing an XML document.
Premature end of file.
ASKER
<!-- version 2 -->
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, ":Envelope/:Body/:GetQuote sResponse/ :GetQuotes Result/:Er rorMsg/fol lowing-sib ling:::Val id");
</cfscript>
An error occured while Parsing an XML document.
Premature end of file.
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, ":Envelope/:Body/:GetQuote
</cfscript>
An error occured while Parsing an XML document.
Premature end of file.
ASKER
<!-- version 1 -->
<!--- Version 1 --->
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, "*:Envelope/*:Body/*:GetQu otesRespon se/*:GetQu otesResult /*:ErrorMs g/followin g-sibling: :*:Valid") ;
</cfscript>
An error occured while Parsing an XML document.
Premature end of file.
Thanks for the help.
<!--- Version 1 --->
<cfscript>
xmlContent = trim(objGet.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, "*:Envelope/*:Body/*:GetQu
</cfscript>
An error occured while Parsing an XML document.
Premature end of file.
Thanks for the help.
> An error occured while Parsing an XML document.
> Premature end of file.
That's something else: apparently your XML is not well-formed. I'm off now for the night (it's 10.30PM here) but I'll look into it tomorrow. The XML you posted here in your first post, btw, was correct, as I tried the XPath that I gave to you before posting, using your original input.
> Premature end of file.
That's something else: apparently your XML is not well-formed. I'm off now for the night (it's 10.30PM here) but I'll look into it tomorrow. The XML you posted here in your first post, btw, was correct, as I tried the XPath that I gave to you before posting, using your original input.
Please use the same content you posted in here in the first place. The code works with that. If not, can you open it in an XML editor to check it for errors? The "Premature end of file" error is almost always caused by a non-closed tag.
ASKER
I am accessing a webservice, I stioll get that premature error. Maybe its how I am setting the variable of the xml.
<cfset strURL = "http://www.awebsite.net/LSPWebService.asmx" />
<cfsavecontent variable="strXML">
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetQuotes xmlns="http://www.awebsite.net">
<_quoteRequest>
<RequestTransactionID>1411 123</Reque stTransact ionID>
<RequestState>AL</RequestS tate>
<RequestClientAge>38</Requ estClientA ge>
<RequestClientTobacco>fals e</Request ClientToba cco>
<RequestSpouseAge>38</Requ estSpouseA ge>
<RequestSpouseTobacco>fals e</Request SpouseToba cco>
<RequestModal>Monthly</Req uestModal>
<RequestFamilyStatus>Spous eOnly</Req uestFamily Status>
<_quoteRequest>
</GetQuotes>
</soap12:Body>
</soap12:Envelope>
</cfsavecontent>
<cfhttp
url="#strURL#"
method="post"
useragent="#CGI.http_user_ agent#"
>
<cfhttpparam
type="XML"
value="#strXML.Trim()#"
/>
</cfhttp>
<cfoutput>#cfhttp.FileCont ent#</cfou tput>
<cfscript>
xmlContent = trim(cfhttp.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, "*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'GetQuotesResponse']/*[loc al-name() = 'GetQuotesResult']/*[local -name() = 'ErrorMsg']/following-sibl ing::*[loc al-name() = 'Valid']");
</cfscript>
<cfset strURL = "http://www.awebsite.net/LSPWebService.asmx" />
<cfsavecontent variable="strXML">
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetQuotes xmlns="http://www.awebsite.net">
<_quoteRequest>
<RequestTransactionID>1411
<RequestState>AL</RequestS
<RequestClientAge>38</Requ
<RequestClientTobacco>fals
<RequestSpouseAge>38</Requ
<RequestSpouseTobacco>fals
<RequestModal>Monthly</Req
<RequestFamilyStatus>Spous
<_quoteRequest>
</GetQuotes>
</soap12:Body>
</soap12:Envelope>
</cfsavecontent>
<cfhttp
url="#strURL#"
method="post"
useragent="#CGI.http_user_
>
<cfhttpparam
type="XML"
value="#strXML.Trim()#"
/>
</cfhttp>
<cfoutput>#cfhttp.FileCont
<cfscript>
xmlContent = trim(cfhttp.FileContent);
xmlContent = XMLParse(xmlContent);
xmlNode = xmlSearch(xmlContent, "*[local-name() = 'Envelope']/*[local-name()
</cfscript>
ASKER
Thanks for the help.
I somehow missed the notification of that last post of you. I see you accepted my answer, but did you get it solved? I mean, did that error go away?
ASKER
I can't seem to get the premature end error to stop it happens everytime i try to XMLParse it.
However you provided me with good answer for the situation my problem probobly lies in the way i am grabbing the xml from their webservice.
<cfhttp
url="#strURL#"
method="post"
useragent="#CGI.http_user_ agent#"
result="objGet"
>
<cfhttpparam
type="XML"
value="#strXML.Trim()#"
/>
</cfhttp>
<cfset MyXMLDoc = #xmlParse(objGet.FileConte nt)# />
However you provided me with good answer for the situation my problem probobly lies in the way i am grabbing the xml from their webservice.
<cfhttp
url="#strURL#"
method="post"
useragent="#CGI.http_user_
result="objGet"
>
<cfhttpparam
type="XML"
value="#strXML.Trim()#"
/>
</cfhttp>
<cfset MyXMLDoc = #xmlParse(objGet.FileConte
Should you really use Trim on the string? Whitespace is not relevant in XML and it doesn't lower the performance.
Can you try to open a local XML file that you know is correct (and don't do anything with it apart from xmlParse), instead of using this http_post method? Then we at least verified that your code is working.
Can you try to open a local XML file that you know is correct (and don't do anything with it apart from xmlParse), instead of using this http_post method? Then we at least verified that your code is working.