Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LINQ Question

Posted on 2011-09-07
9
Medium Priority
?
211 Views
Last Modified: 2012-06-22
Dear Experts,

I have a requirement.I need to extract a value and pass it as a string to a method which writes an XML file.

Current method call:

xPurchaseOrder.WriteElementString(PurchaseOrderXML.KIT_LEVEL_INVOICE_ACCOUNT_CODE, XML_NS, kitInfo.kitaccount);

sample Output xml looks like this
   <acctcode>MyNewCode</acctcode>

------------------------

String variable that gets assigned from a DB call (KitInfo.WorkTicket). I would like to parse it one after another and create a statement like above WriteElementString() for each and every xml tags it has like below

------------------
DB call gives me a var char output of this xml file and assigns to Kitinfo.workticket object
<WorkTicket>
<ComponentsList>
<KitSummary KitID="62-4854-PER-DC/FL” Provider =”SRC” />

 <Kit ComponentID="62-1615" QTY="4.00000” Provider =” SRC”/>  
<Kit ComponentID="62-4854" QTY="4.00000" "  Provider =” Vendor1”/>  
  .
  .
 <Kit ComponentID="62-6137-DC/FL" QTY="4.00000" "  Provider =” Vendor2”/>  
 <Kit ComponentID="62-7340" QTY="4.00000" "  Provider =” Vendor3”/>  

</ComponentsList>

< AssemblyInstructions="insert item #'s 62-6137-DC/FL, 62-7340 and 62-1615 into welcome envelope (62-4854) Stack completed kits together and rubber band with TAN rubber band" />

</WorkTicket>

-----------

sorry if it is too much confusing..it is really hard to explain
0
Comment
Question by:SubbuUSA
  • 4
  • 3
  • 2
9 Comments
 
LVL 27

Expert Comment

by:MikeToole
ID: 36501535
>>> String variable that gets assigned from a DB call (KitInfo.WorkTicket).
>>> DB call gives me a var char output of this xml file and assigns to Kitinfo.workticket object
I'm confused, is it a string variable, var char output, or an object?
What does the KitInfo type look like?
How do you map between the WorkTicket elements and the element names in the PurchaseOrderXML?
0
 

Author Comment

by:SubbuUSA
ID: 36502211
@MikeToole

First of all, I appreciate lending your help to me. I know it is little confusing but I will try to my best to explain with the amount of  english proficiency I have :)

My requirement is to generate an XML file.  The below method will write to my xml file generation. This property (KIT_LEVEL_INVOICE_ACCOUNT_CODE) sets my tagname like this <acctcode> and this property (kitInfo.kitaccount) will contain the string data obtained from the DB call. In this case it will have the value as 'MyNewCode'

------------

xPurchaseOrder.WriteElementString(PurchaseOrderXML.KIT_LEVEL_INVOICE_ACCOUNT_CODE, XML_NS, kitInfo.kitaccount);

sample Output xml looks like this    <acctcode>MyNewCode</acctcode>

PurchseOrderXML class will contain

{
KIT_LEVEL_INVOICE_ACCOUNT_CODE = "acctcode";
so on...
}

--------------


Before writing my XML file, My DB call would fetch data from the rowset and populate the KitInfo object. Which will have String, bool, int  declarations.

Public class kitinfo: IDataAccessGetValue
{
int accno{get; set}
string acctcode{get; set}
string workTicket{get; set}
}

When My DB call fills this Data classes, KitInfo object will contain a value which will be typically an XML tags like this below

<WorkTicket><ComponentsList><KitSummary KitID="62-4854-PER-DC/FL” Provider =”SRC” /><Kit ComponentID="62-1615" QTY="4.00000” Provider =” SRC”/><Kit ComponentID="62-4854" QTY="4.00000" "  Provider =” Vendor1”/></ComponentsList>< AssemblyInstructions="insert item #'s 62-6137-DC/FL, 62-7340 and 62-1615 into welcome envelope (62-4854) Stack completed kits together and rubber band with TAN rubber band" /></WorkTicket>

I will assign this to a string variable in my code behind.
String workTicket data = XML Tags get asigned to variable ;

What I need here is:

I would like to parse each and every tags and  assign it like this  <acctcode>MyNewCode</acctcode>

At the same time I do not want to disintegerate the attributes to split from the element tags. here ,
the Qty and Provider should be tied to this component and not as separate tags.
 <Kit ComponentID="62-1615" QTY="4.00000” Provider =” SRC”/>  

I would like my work ticket to fit in the XML generation.  I will not have any problem if it is a single string  variable. Too many XML tags in the string variable is what makes it complex to work.

I hope it helps.
0
 
LVL 25

Expert Comment

by:apeter
ID: 36505871
Why can't try using Linq to XML to parse the string ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:SubbuUSA
ID: 36505966
@apeter

Could you please help me..I would have definitely done if I would have known it
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 36511566
Can you post the detail layout of the output required for the sample workticket?
0
 
LVL 25

Expert Comment

by:apeter
ID: 36513667
What is the xml you have and what is the value u want to extract from it ?
0
 

Author Comment

by:SubbuUSA
ID: 36514358
@MikeToole and @apeter:

My computer crashed and could not respond today.


I was even thinking of appending option..let me know whether that will work out or not?



Sample XML
----------------
 <acctcode>MyNewCode</acctcode>
 <acctpswd>Password</acctpswd>
 <accno>1234</accno>

work ticket XML from a variable has to be appended with the above statements

<WorkTicket>
<ComponentsList>
<KitSummary KitID="62-4854-PER-DC/FL” Provider =”SRC” />
 <Kit ComponentID="62-1615" QTY="4.00000” Provider =” SRC”/>  
<Kit ComponentID="62-4854" QTY="4.00000" "  Provider =” Vendor1”/>  
  .
  .
 <Kit ComponentID="62-6137-DC/FL" QTY="4.00000" "  Provider =” Vendor2”/>  
 <Kit ComponentID="62-7340" QTY="4.00000" "  Provider =” Vendor3”/>  

</ComponentsList>

< AssemblyInstructions="insert item #'s 62-6137-DC/FL, 62-7340 and 62-1615 into welcome envelope (62-4854) Stack completed kits together and rubber band with TAN rubber band" />

</WorkTicket>
0
 
LVL 27

Accepted Solution

by:
MikeToole earned 2000 total points
ID: 36518764
To help you need to define the Target output required.
You've reposted what I understand to be the sample workticket input - which, by the way, contains invalid XML:
< AssemblyInstructions="insert item #'s 62-6137-DC/FL, 62-7340 and 62-1615 into welcome envelope (62-4854) Stack completed kits together and rubber band with TAN rubber band" />

Making some assumptions about what you want, the attached code produces the following output:

<PurchaseOrder>
  <acctcode>MyNewCode</acctcode>
  <acctpswd>Password</acctpswd>
  <accno>1234</accno>
  <WorkTicket>
    <ComponentsList>
      <KitSummary KitID="62-4854-PER-DC/FL" Provider="SRC" />
      <Kit ComponentID="62-1615" QTY="4.00000" Provider="SRC" />
      <Kit ComponentID="62-4854" QTY="4.00000" Provider="Vendor1" />
      <Kit ComponentID="62-6137-DC/FL" QTY="4.00000" Provider="Vendor2" />
      <Kit ComponentID="62-7340" QTY="4.00000" Provider="Vendor3" />
    </ComponentsList>
    <AssemblyInstructions>insert item #'s 62-6137-DC/FL, 62-7340 and 62-1615 into welcome envelope (62-4854) Stack completed kits together and rubber
band with TAN rubber band"
                    </AssemblyInstructions>
  </WorkTicket>
</PurchaseOrder>
public static void Test()
        {
            XElement X = XElement.Parse(@"<PurchaseOrder><acctcode>MyNewCode</acctcode> <acctpswd>Password</acctpswd>  <accno>1234</accno> </PurchaseOrder>");
            var WT = XElement.Parse(
                    @"<WorkTicket>
                        <ComponentsList>
                            <KitSummary KitID=""62-4854-PER-DC/FL"" Provider =""SRC"" /> 
                            <Kit ComponentID=""62-1615"" QTY=""4.00000"" Provider=""SRC""/>  
                            <Kit ComponentID=""62-4854"" QTY=""4.00000"" Provider=""Vendor1""/>  
                            <Kit ComponentID=""62-6137-DC/FL"" QTY=""4.00000"" Provider=""Vendor2""/>   
                            <Kit ComponentID=""62-7340"" QTY=""4.00000"" Provider=""Vendor3""/>  
                        </ComponentsList>
                    <AssemblyInstructions>insert item #'s 62-6137-DC/FL, 62-7340 and 62-1615 into welcome envelope (62-4854) Stack completed kits together and rubber band with TAN rubber band""
                    </AssemblyInstructions>
                    </WorkTicket>");

            X.Add(WT);
            Console.Write(X.ToString());
        }

Open in new window

0
 

Author Closing Comment

by:SubbuUSA
ID: 36523246
Thanks a lot for your help
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

972 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