Converting a CSV file into appropriate XML formatHow to output MySQL query results in CSV format?Dealing with commas in a CSV fileSave PL/pgSQL output from PostgreSQL to a CSV fileHow do I parse XML in Python?What does <![CDATA[]]> in XML mean?How to import CSV file data into a PostgreSQL table?How do you parse and process HTML/XML in PHP?Excel to CSV with UTF8 encodingHow To Auto-Format / Indent XML/HTML in Notepad++Writing a pandas DataFrame to CSV file

Disambiguation of "nobis vobis" and "nobis nobis"

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

I can see my two means are different. What information can a t test add?

Was there ever a treaty between 2 entities with significantly different translations to the detriment of one party?

Understanding Parallelize methods

What to say to a student who has failed?

Immutable builder and updater

Nothing like a good ol' game of ModTen

Is there any way to keep a player from killing an NPC?

Are there any elected officials in the U.S. who are not legislators, judges, or constitutional officers?

The Knight's estate

Round towards zero

“T” in subscript in formulas

What are some interesting features that are common cross-linguistically but don't exist in English?

What would be the challenges to taking off and landing a typical passenger jet at FL300?

I don't have the theoretical background in my PhD topic. I can't justify getting the degree

Dealing with an extrovert co-worker

Architectural feasibility of a tiered circular stone keep

How do you harvest carrots in creative mode?

Numbers Decrease while Letters Increase

Would the Republic of Ireland and Northern Ireland be interested in reuniting?

Can a Rogue PC teach an NPC to perform Sneak Attack?

How do I request a longer than normal leave of absence period for my wedding?

Is using a hyperlink to close a modal a poor design decision?



Converting a CSV file into appropriate XML format


How to output MySQL query results in CSV format?Dealing with commas in a CSV fileSave PL/pgSQL output from PostgreSQL to a CSV fileHow do I parse XML in Python?What does <![CDATA[]]> in XML mean?How to import CSV file data into a PostgreSQL table?How do you parse and process HTML/XML in PHP?Excel to CSV with UTF8 encodingHow To Auto-Format / Indent XML/HTML in Notepad++Writing a pandas DataFrame to CSV file






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to get some tab-delimited CSV files into an XML via PowerShell, and I'm struggling to make sense of it all. I'm 100% sure it's something really simple I'm missing, so help would be massively appreciated. I'm very close but just can't get over the final hurdle.



I essentially want this script to iterate through a tab-delimited CSV it's pointed at ($path), take each line off of the CSV and put the data into an XML sheet ($xmlpath).



CSV example:




"Name" "Item" "Purchase Price"
"Jimmy Smits" "Egg" "£40"
"Edward Price" "KumQuat" "£6000"
"Timmy Mallet" "Bug" "£2"
"Edgar Allen Poe" "Weird" "0"
"2Pac Shakur" "Eggnog" ""


XML output template example:



<registration>
<Individual>
<Name></Name>
<Item></Item>
<Purchase Price></Purchase Price>
</Individual>
</registration>


And this is what I've been poking about with



$data = Import-Csv -Path $path -Delimiter "`t"

$xmlnames = $data | Select-Object "Name"
$xmlitems = $data | Select-Object "Item"
$xmlprice = $data | Select-Object "Purchase Price"

$entryTemplate = @'
<individual>
<Name>$($xmlnames.Name)</Name>
<Item>$($xmlitems.Item)</Item>
<Purchase Price>$($xmlprice."Purchase Price")</Purchase Price>
</individual>
'@

$xml = $data | ForEach-Object
$ExecutionContext.InvokeCommand.ExpandString($entrytemplate)

$xml | Out-File $xmlpath


Which then puts out;



<Individual>
<Name>Jimmy Smits Edward Price Timmy Mallet Edgar Allen Poe 2Pac Shakur</Name>
<Item>System.Object IList.Item(int index) get;set;</Item>
<Purchase Price>£40 £6000 £2 0 </Purchase Price>
</Individual>


So somewhere I'm messing up stupidly on two things;



  1. The $data | Select-Object 'thing' is giving me all of the list of 'things' rather than iterating through each of the 'things' and listing them one per XML entry. Yet is giving me the correct number of entries?

  2. My 'Items' are being listed as system objects (not values), despite being treated identically to everything else.









share|improve this question


























  • when you type $data[0] ...it should output the first row of the csv...if not, the csv is not well-formed... make sure it is actually a csv file. Then proceed with other steps.

    – Kiran
    Mar 27 at 18:03

















1















I'm trying to get some tab-delimited CSV files into an XML via PowerShell, and I'm struggling to make sense of it all. I'm 100% sure it's something really simple I'm missing, so help would be massively appreciated. I'm very close but just can't get over the final hurdle.



I essentially want this script to iterate through a tab-delimited CSV it's pointed at ($path), take each line off of the CSV and put the data into an XML sheet ($xmlpath).



CSV example:




"Name" "Item" "Purchase Price"
"Jimmy Smits" "Egg" "£40"
"Edward Price" "KumQuat" "£6000"
"Timmy Mallet" "Bug" "£2"
"Edgar Allen Poe" "Weird" "0"
"2Pac Shakur" "Eggnog" ""


XML output template example:



<registration>
<Individual>
<Name></Name>
<Item></Item>
<Purchase Price></Purchase Price>
</Individual>
</registration>


And this is what I've been poking about with



$data = Import-Csv -Path $path -Delimiter "`t"

$xmlnames = $data | Select-Object "Name"
$xmlitems = $data | Select-Object "Item"
$xmlprice = $data | Select-Object "Purchase Price"

$entryTemplate = @'
<individual>
<Name>$($xmlnames.Name)</Name>
<Item>$($xmlitems.Item)</Item>
<Purchase Price>$($xmlprice."Purchase Price")</Purchase Price>
</individual>
'@

$xml = $data | ForEach-Object
$ExecutionContext.InvokeCommand.ExpandString($entrytemplate)

$xml | Out-File $xmlpath


Which then puts out;



<Individual>
<Name>Jimmy Smits Edward Price Timmy Mallet Edgar Allen Poe 2Pac Shakur</Name>
<Item>System.Object IList.Item(int index) get;set;</Item>
<Purchase Price>£40 £6000 £2 0 </Purchase Price>
</Individual>


So somewhere I'm messing up stupidly on two things;



  1. The $data | Select-Object 'thing' is giving me all of the list of 'things' rather than iterating through each of the 'things' and listing them one per XML entry. Yet is giving me the correct number of entries?

  2. My 'Items' are being listed as system objects (not values), despite being treated identically to everything else.









share|improve this question


























  • when you type $data[0] ...it should output the first row of the csv...if not, the csv is not well-formed... make sure it is actually a csv file. Then proceed with other steps.

    – Kiran
    Mar 27 at 18:03













1












1








1


0






I'm trying to get some tab-delimited CSV files into an XML via PowerShell, and I'm struggling to make sense of it all. I'm 100% sure it's something really simple I'm missing, so help would be massively appreciated. I'm very close but just can't get over the final hurdle.



I essentially want this script to iterate through a tab-delimited CSV it's pointed at ($path), take each line off of the CSV and put the data into an XML sheet ($xmlpath).



CSV example:




"Name" "Item" "Purchase Price"
"Jimmy Smits" "Egg" "£40"
"Edward Price" "KumQuat" "£6000"
"Timmy Mallet" "Bug" "£2"
"Edgar Allen Poe" "Weird" "0"
"2Pac Shakur" "Eggnog" ""


XML output template example:



<registration>
<Individual>
<Name></Name>
<Item></Item>
<Purchase Price></Purchase Price>
</Individual>
</registration>


And this is what I've been poking about with



$data = Import-Csv -Path $path -Delimiter "`t"

$xmlnames = $data | Select-Object "Name"
$xmlitems = $data | Select-Object "Item"
$xmlprice = $data | Select-Object "Purchase Price"

$entryTemplate = @'
<individual>
<Name>$($xmlnames.Name)</Name>
<Item>$($xmlitems.Item)</Item>
<Purchase Price>$($xmlprice."Purchase Price")</Purchase Price>
</individual>
'@

$xml = $data | ForEach-Object
$ExecutionContext.InvokeCommand.ExpandString($entrytemplate)

$xml | Out-File $xmlpath


Which then puts out;



<Individual>
<Name>Jimmy Smits Edward Price Timmy Mallet Edgar Allen Poe 2Pac Shakur</Name>
<Item>System.Object IList.Item(int index) get;set;</Item>
<Purchase Price>£40 £6000 £2 0 </Purchase Price>
</Individual>


So somewhere I'm messing up stupidly on two things;



  1. The $data | Select-Object 'thing' is giving me all of the list of 'things' rather than iterating through each of the 'things' and listing them one per XML entry. Yet is giving me the correct number of entries?

  2. My 'Items' are being listed as system objects (not values), despite being treated identically to everything else.









share|improve this question
















I'm trying to get some tab-delimited CSV files into an XML via PowerShell, and I'm struggling to make sense of it all. I'm 100% sure it's something really simple I'm missing, so help would be massively appreciated. I'm very close but just can't get over the final hurdle.



I essentially want this script to iterate through a tab-delimited CSV it's pointed at ($path), take each line off of the CSV and put the data into an XML sheet ($xmlpath).



CSV example:




"Name" "Item" "Purchase Price"
"Jimmy Smits" "Egg" "£40"
"Edward Price" "KumQuat" "£6000"
"Timmy Mallet" "Bug" "£2"
"Edgar Allen Poe" "Weird" "0"
"2Pac Shakur" "Eggnog" ""


XML output template example:



<registration>
<Individual>
<Name></Name>
<Item></Item>
<Purchase Price></Purchase Price>
</Individual>
</registration>


And this is what I've been poking about with



$data = Import-Csv -Path $path -Delimiter "`t"

$xmlnames = $data | Select-Object "Name"
$xmlitems = $data | Select-Object "Item"
$xmlprice = $data | Select-Object "Purchase Price"

$entryTemplate = @'
<individual>
<Name>$($xmlnames.Name)</Name>
<Item>$($xmlitems.Item)</Item>
<Purchase Price>$($xmlprice."Purchase Price")</Purchase Price>
</individual>
'@

$xml = $data | ForEach-Object
$ExecutionContext.InvokeCommand.ExpandString($entrytemplate)

$xml | Out-File $xmlpath


Which then puts out;



<Individual>
<Name>Jimmy Smits Edward Price Timmy Mallet Edgar Allen Poe 2Pac Shakur</Name>
<Item>System.Object IList.Item(int index) get;set;</Item>
<Purchase Price>£40 £6000 £2 0 </Purchase Price>
</Individual>


So somewhere I'm messing up stupidly on two things;



  1. The $data | Select-Object 'thing' is giving me all of the list of 'things' rather than iterating through each of the 'things' and listing them one per XML entry. Yet is giving me the correct number of entries?

  2. My 'Items' are being listed as system objects (not values), despite being treated identically to everything else.






xml powershell csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 17:45









Ansgar Wiechers

153k15 gold badges144 silver badges205 bronze badges




153k15 gold badges144 silver badges205 bronze badges










asked Mar 27 at 17:37









HonkytonkHonkytonk

83 bronze badges




83 bronze badges















  • when you type $data[0] ...it should output the first row of the csv...if not, the csv is not well-formed... make sure it is actually a csv file. Then proceed with other steps.

    – Kiran
    Mar 27 at 18:03

















  • when you type $data[0] ...it should output the first row of the csv...if not, the csv is not well-formed... make sure it is actually a csv file. Then proceed with other steps.

    – Kiran
    Mar 27 at 18:03
















when you type $data[0] ...it should output the first row of the csv...if not, the csv is not well-formed... make sure it is actually a csv file. Then proceed with other steps.

– Kiran
Mar 27 at 18:03





when you type $data[0] ...it should output the first row of the csv...if not, the csv is not well-formed... make sure it is actually a csv file. Then proceed with other steps.

– Kiran
Mar 27 at 18:03












2 Answers
2






active

oldest

votes


















2















The three statements



$xmlnames = $data | Select-Object "Name"
$xmlitems = $data | Select-Object "Item"
$xmlprice = $data | Select-Object "Purchase Price"


give you lists of custom objects with just one property. Using these lists in your template inserts all values into a tag with each iteration. What you want is just the value from the current iteration, hence creating the lists before doesn't do you any good. What you actually want is the current object during each iteration of the loop.



In case of $xmlitems you're also running into a PowerShell gotcha, because the variables $xmlnames, $xmlitems, and $xmlprice are arrays. When using dot-access on an array PowerShell is doing something that is called member enumeration. Essentially $xmlnames.Name won't give you the value of the property Name of the array object, but the value of the property Name of all array elements.



Member enumeration only works if the array object itself doesn't have a member of that name, though. Which brings us back to $xmlitems. For that variable you're trying to get the value of the property Item of the array elements. However, the array object actually has a method Item(), so $xmlitems.Item tries to invoke that method instead of the Item property of the array elements. But since the method is overloaded and the invocation is missing parentheses ($xmlitems.Item instead of $xmlitems.Item()) PowerShell shows you the method definition instead.



Remove the Select-Object statements and replace the array variables in your XML fragment template with the "current object" variable $_ and the code will do what you want.



$entryTemplate = @'
<individual>
<Name>$($_.Name)</Name>
<Item>$($_.Item)</Item>
<Purchase Price>$($_."Purchase Price")</Purchase Price>
</individual>
'@





share|improve this answer

























  • 'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

    – Honkytonk
    Mar 28 at 9:05


















1















You can also use "LINQ to XML" to create xml.



using namespace "System.Xml.Linq"
Add-Type -AssemblyName System.Xml.Linq

[XElement]::new("registration", @(
Import-Csv -Path $path -Delimiter "`t" | foreach
[XElement]::new("Individual",
[XElement]::new("Name", $_.Name),
[XElement]::new("Item", $_.Item),
[XElement]::new("PurchasePrice", $_."Purchase Price"))

)).Save($xmlpath)





share|improve this answer





























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383413%2fconverting-a-csv-file-into-appropriate-xml-format%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2















    The three statements



    $xmlnames = $data | Select-Object "Name"
    $xmlitems = $data | Select-Object "Item"
    $xmlprice = $data | Select-Object "Purchase Price"


    give you lists of custom objects with just one property. Using these lists in your template inserts all values into a tag with each iteration. What you want is just the value from the current iteration, hence creating the lists before doesn't do you any good. What you actually want is the current object during each iteration of the loop.



    In case of $xmlitems you're also running into a PowerShell gotcha, because the variables $xmlnames, $xmlitems, and $xmlprice are arrays. When using dot-access on an array PowerShell is doing something that is called member enumeration. Essentially $xmlnames.Name won't give you the value of the property Name of the array object, but the value of the property Name of all array elements.



    Member enumeration only works if the array object itself doesn't have a member of that name, though. Which brings us back to $xmlitems. For that variable you're trying to get the value of the property Item of the array elements. However, the array object actually has a method Item(), so $xmlitems.Item tries to invoke that method instead of the Item property of the array elements. But since the method is overloaded and the invocation is missing parentheses ($xmlitems.Item instead of $xmlitems.Item()) PowerShell shows you the method definition instead.



    Remove the Select-Object statements and replace the array variables in your XML fragment template with the "current object" variable $_ and the code will do what you want.



    $entryTemplate = @'
    <individual>
    <Name>$($_.Name)</Name>
    <Item>$($_.Item)</Item>
    <Purchase Price>$($_."Purchase Price")</Purchase Price>
    </individual>
    '@





    share|improve this answer

























    • 'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

      – Honkytonk
      Mar 28 at 9:05















    2















    The three statements



    $xmlnames = $data | Select-Object "Name"
    $xmlitems = $data | Select-Object "Item"
    $xmlprice = $data | Select-Object "Purchase Price"


    give you lists of custom objects with just one property. Using these lists in your template inserts all values into a tag with each iteration. What you want is just the value from the current iteration, hence creating the lists before doesn't do you any good. What you actually want is the current object during each iteration of the loop.



    In case of $xmlitems you're also running into a PowerShell gotcha, because the variables $xmlnames, $xmlitems, and $xmlprice are arrays. When using dot-access on an array PowerShell is doing something that is called member enumeration. Essentially $xmlnames.Name won't give you the value of the property Name of the array object, but the value of the property Name of all array elements.



    Member enumeration only works if the array object itself doesn't have a member of that name, though. Which brings us back to $xmlitems. For that variable you're trying to get the value of the property Item of the array elements. However, the array object actually has a method Item(), so $xmlitems.Item tries to invoke that method instead of the Item property of the array elements. But since the method is overloaded and the invocation is missing parentheses ($xmlitems.Item instead of $xmlitems.Item()) PowerShell shows you the method definition instead.



    Remove the Select-Object statements and replace the array variables in your XML fragment template with the "current object" variable $_ and the code will do what you want.



    $entryTemplate = @'
    <individual>
    <Name>$($_.Name)</Name>
    <Item>$($_.Item)</Item>
    <Purchase Price>$($_."Purchase Price")</Purchase Price>
    </individual>
    '@





    share|improve this answer

























    • 'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

      – Honkytonk
      Mar 28 at 9:05













    2














    2










    2









    The three statements



    $xmlnames = $data | Select-Object "Name"
    $xmlitems = $data | Select-Object "Item"
    $xmlprice = $data | Select-Object "Purchase Price"


    give you lists of custom objects with just one property. Using these lists in your template inserts all values into a tag with each iteration. What you want is just the value from the current iteration, hence creating the lists before doesn't do you any good. What you actually want is the current object during each iteration of the loop.



    In case of $xmlitems you're also running into a PowerShell gotcha, because the variables $xmlnames, $xmlitems, and $xmlprice are arrays. When using dot-access on an array PowerShell is doing something that is called member enumeration. Essentially $xmlnames.Name won't give you the value of the property Name of the array object, but the value of the property Name of all array elements.



    Member enumeration only works if the array object itself doesn't have a member of that name, though. Which brings us back to $xmlitems. For that variable you're trying to get the value of the property Item of the array elements. However, the array object actually has a method Item(), so $xmlitems.Item tries to invoke that method instead of the Item property of the array elements. But since the method is overloaded and the invocation is missing parentheses ($xmlitems.Item instead of $xmlitems.Item()) PowerShell shows you the method definition instead.



    Remove the Select-Object statements and replace the array variables in your XML fragment template with the "current object" variable $_ and the code will do what you want.



    $entryTemplate = @'
    <individual>
    <Name>$($_.Name)</Name>
    <Item>$($_.Item)</Item>
    <Purchase Price>$($_."Purchase Price")</Purchase Price>
    </individual>
    '@





    share|improve this answer













    The three statements



    $xmlnames = $data | Select-Object "Name"
    $xmlitems = $data | Select-Object "Item"
    $xmlprice = $data | Select-Object "Purchase Price"


    give you lists of custom objects with just one property. Using these lists in your template inserts all values into a tag with each iteration. What you want is just the value from the current iteration, hence creating the lists before doesn't do you any good. What you actually want is the current object during each iteration of the loop.



    In case of $xmlitems you're also running into a PowerShell gotcha, because the variables $xmlnames, $xmlitems, and $xmlprice are arrays. When using dot-access on an array PowerShell is doing something that is called member enumeration. Essentially $xmlnames.Name won't give you the value of the property Name of the array object, but the value of the property Name of all array elements.



    Member enumeration only works if the array object itself doesn't have a member of that name, though. Which brings us back to $xmlitems. For that variable you're trying to get the value of the property Item of the array elements. However, the array object actually has a method Item(), so $xmlitems.Item tries to invoke that method instead of the Item property of the array elements. But since the method is overloaded and the invocation is missing parentheses ($xmlitems.Item instead of $xmlitems.Item()) PowerShell shows you the method definition instead.



    Remove the Select-Object statements and replace the array variables in your XML fragment template with the "current object" variable $_ and the code will do what you want.



    $entryTemplate = @'
    <individual>
    <Name>$($_.Name)</Name>
    <Item>$($_.Item)</Item>
    <Purchase Price>$($_."Purchase Price")</Purchase Price>
    </individual>
    '@






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 27 at 18:11









    Ansgar WiechersAnsgar Wiechers

    153k15 gold badges144 silver badges205 bronze badges




    153k15 gold badges144 silver badges205 bronze badges















    • 'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

      – Honkytonk
      Mar 28 at 9:05

















    • 'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

      – Honkytonk
      Mar 28 at 9:05
















    'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

    – Honkytonk
    Mar 28 at 9:05





    'Doh' of course! I was sure the select-objects were causing the multiple selections, but I couldn't wrap my head around the methods/arrays. Thanks for taking the time to explain it properly for me, this is now working perfectly!

    – Honkytonk
    Mar 28 at 9:05













    1















    You can also use "LINQ to XML" to create xml.



    using namespace "System.Xml.Linq"
    Add-Type -AssemblyName System.Xml.Linq

    [XElement]::new("registration", @(
    Import-Csv -Path $path -Delimiter "`t" | foreach
    [XElement]::new("Individual",
    [XElement]::new("Name", $_.Name),
    [XElement]::new("Item", $_.Item),
    [XElement]::new("PurchasePrice", $_."Purchase Price"))

    )).Save($xmlpath)





    share|improve this answer































      1















      You can also use "LINQ to XML" to create xml.



      using namespace "System.Xml.Linq"
      Add-Type -AssemblyName System.Xml.Linq

      [XElement]::new("registration", @(
      Import-Csv -Path $path -Delimiter "`t" | foreach
      [XElement]::new("Individual",
      [XElement]::new("Name", $_.Name),
      [XElement]::new("Item", $_.Item),
      [XElement]::new("PurchasePrice", $_."Purchase Price"))

      )).Save($xmlpath)





      share|improve this answer





























        1














        1










        1









        You can also use "LINQ to XML" to create xml.



        using namespace "System.Xml.Linq"
        Add-Type -AssemblyName System.Xml.Linq

        [XElement]::new("registration", @(
        Import-Csv -Path $path -Delimiter "`t" | foreach
        [XElement]::new("Individual",
        [XElement]::new("Name", $_.Name),
        [XElement]::new("Item", $_.Item),
        [XElement]::new("PurchasePrice", $_."Purchase Price"))

        )).Save($xmlpath)





        share|improve this answer















        You can also use "LINQ to XML" to create xml.



        using namespace "System.Xml.Linq"
        Add-Type -AssemblyName System.Xml.Linq

        [XElement]::new("registration", @(
        Import-Csv -Path $path -Delimiter "`t" | foreach
        [XElement]::new("Individual",
        [XElement]::new("Name", $_.Name),
        [XElement]::new("Item", $_.Item),
        [XElement]::new("PurchasePrice", $_."Purchase Price"))

        )).Save($xmlpath)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 22 at 4:51

























        answered Mar 27 at 19:01









        rokumarurokumaru

        8581 gold badge3 silver badges9 bronze badges




        8581 gold badge3 silver badges9 bronze badges






























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383413%2fconverting-a-csv-file-into-appropriate-xml-format%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현