Solved

Title: CFMX 7 converting XML input stream to query object

Posted on 2006-06-22
4
179 Views
Last Modified: 2013-12-24
How can I convert this into a query object?

                  <ActiveContracts Contract="SP010000D0347" DeliveryOrder="0126" CLIN="0034AA" Qty="144" UnitOfIssue="PR" NSN="8405010760772" DeliveryDate="" ProjectCode="" Requisition="              " RequisitionSuffix="" ShipToDoDAAC="UY3246" DistrCode="" PriorityCode="" AwardDate="01/01/2003" FastPayCode="N" AdminOffice="S0701A" UnitPrice="12.00000" QtyVarianceAllowed=".00000" InspectionPoint="S" AcceptancePoint="S" FOBPoint="D" DiscountCode="0000" PayOffice="SC0100" GFMUnitPrice=".00000" BailmentCode="" BuyerName="" BuyerPhone="" BuyerEmail="" CaseLotQty="12"/>

Thank You
0
Comment
Question by:cottyengland
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:DanielSKim
ID: 16965202
is this what you are looking for?

<cfset xmlString = '<ActiveContracts Contract="SP010000D0347" DeliveryOrder="0126" CLIN="0034AA" Qty="144" UnitOfIssue="PR" NSN="8405010760772" DeliveryDate="" ProjectCode="" Requisition="              " RequisitionSuffix="" ShipToDoDAAC="UY3246" DistrCode="" PriorityCode="" AwardDate="01/01/2003" FastPayCode="N" AdminOffice="S0701A" UnitPrice="12.00000" QtyVarianceAllowed=".00000" InspectionPoint="S" AcceptancePoint="S" FOBPoint="D" DiscountCode="0000" PayOffice="SC0100" GFMUnitPrice=".00000" BailmentCode="" BuyerName="" BuyerPhone="" BuyerEmail="" CaseLotQty="12"/>' />

<cfset myXmlAttributes = xmlParse(xmlString).xmlRoot.xmlAttributes />
<cfset myQueryObject = QueryNew(StructKeyList(myXmlAttributes)) />
<cfset QueryAddRow(myQueryObject) />

<cfloop collection="#myXmlAttributes#" item="a">
      <cfset QuerySetCell(myQueryObject, a, myXmlAttributes[a]) />
</cfloop>
0
 

Author Comment

by:cottyengland
ID: 16967973
YEs it is but how do I parse more than 1 record.. for example

<ActiveContracts Contract="SP010000D0347" DeliveryOrder="0126" CLIN="0034AA" Qty="144" UnitOfIssue="PR" NSN="8405010760772" DeliveryDate="" ProjectCode="" Requisition="              " RequisitionSuffix="" ShipToDoDAAC="UY3246" DistrCode="" PriorityCode="" AwardDate="01/01/2003" FastPayCode="N" AdminOffice="S0701A" UnitPrice="12.00000" QtyVarianceAllowed=".00000" InspectionPoint="S" AcceptancePoint="S" FOBPoint="D" DiscountCode="0000" PayOffice="SC0100" GFMUnitPrice=".00000" BailmentCode="" BuyerName="" BuyerPhone="" BuyerEmail="" CaseLotQty="12"/>
ActiveContracts Contract="SP010000D0347" DeliveryOrder="0126" CLIN="0034AA" Qty="144" UnitOfIssue="PR" NSN="8405010760772" DeliveryDate="" ProjectCode="" Requisition="              " RequisitionSuffix="" ShipToDoDAAC="UY3246" DistrCode="" PriorityCode="" AwardDate="01/01/2003" FastPayCode="N" AdminOffice="S0701A" UnitPrice="12.00000" QtyVarianceAllowed=".00000" InspectionPoint="S" AcceptancePoint="S" FOBPoint="D" DiscountCode="0000" PayOffice="SC0100" GFMUnitPrice=".00000" BailmentCode="" BuyerName="" BuyerPhone="" BuyerEmail="" CaseLotQty="12"/>

I see the cfloop collecting the data elements.... where or how would you use cfloop to loop through "ActiveContracts". I could have as many as 100 seperate "ActiveContracts" in an XML.

Thanks
0
 
LVL 15

Accepted Solution

by:
DanielSKim earned 500 total points
ID: 16968397
I'm assuming you have a root element for the xml, meaning the full xml for two ActiveContracts elements would look like this:

<cfset xmlString = '<rootName><ActiveContracts Contract="SP010000D0347" DeliveryOrder="0126" CLIN="0034AA" Qty="144" UnitOfIssue="PR" NSN="8405010760772" DeliveryDate="" ProjectCode="" Requisition="              " RequisitionSuffix="" ShipToDoDAAC="UY3246" DistrCode="" PriorityCode="" AwardDate="01/01/2003" FastPayCode="N" AdminOffice="S0701A" UnitPrice="12.00000" QtyVarianceAllowed=".00000" InspectionPoint="S" AcceptancePoint="S" FOBPoint="D" DiscountCode="0000" PayOffice="SC0100" GFMUnitPrice=".00000" BailmentCode="" BuyerName="" BuyerPhone="" BuyerEmail="" CaseLotQty="12"/><ActiveContracts Contract="SP010000D0347" DeliveryOrder="0126" CLIN="0034AA" Qty="144" UnitOfIssue="PR" NSN="8405010760772" DeliveryDate="" ProjectCode="" Requisition="              " RequisitionSuffix="" ShipToDoDAAC="UY3246" DistrCode="" PriorityCode="" AwardDate="01/01/2003" FastPayCode="N" AdminOffice="S0701A" UnitPrice="12.00000" QtyVarianceAllowed=".00000" InspectionPoint="S" AcceptancePoint="S" FOBPoint="D" DiscountCode="0000" PayOffice="SC0100" GFMUnitPrice=".00000" BailmentCode="" BuyerName="" BuyerPhone="" BuyerEmail="" CaseLotQty="12"/></rootName>' />

If not, just concatenate an opening and closing root tag to the entire string (in the above example, is used "rootName"). Then the following should work:

<cfif isXML(xmlString)>

      <cfset myXmlChildren = xmlParse(xmlString).xmlRoot.xmlChildren />
      <cfset myQueryObject = QueryNew(StructKeyList(myXmlChildren[1].xmlAttributes)) />
      
      <cfloop from="1" to="#ArrayLen(myXmlChildren)#" index="i">
      
            <cfset myXmlAttributes = myXmlChildren[i].xmlAttributes />
            <cfset QueryAddRow(myQueryObject) />
            
            <cfloop collection="#myXmlAttributes#" item="a">
                  <cfset QuerySetCell(myQueryObject, a, myXmlAttributes[a], i) />
            </cfloop>
            
      </cfloop>
      
</cfif>
0
 

Author Comment

by:cottyengland
ID: 16969274
You are very good. Thank You
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to solve ssl error handshake failure alert on IE 1 229
ColdFusion Rereplace 3 81
whm high memory usage in processes 7 103
app server have enough resources... 2 52
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question