Solved

Title: CFMX 7 converting XML input stream to query object

Posted on 2006-06-22
4
176 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

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
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 …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now