?
Solved

Title: CFMX 7 converting XML input stream to query object

Posted on 2006-06-22
4
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

765 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