Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. generating a unique value and adding it to a group of elements

generating a unique value and adding it to a group of elements

Scheduled Pinned Locked Moved XML / XSL
csharpbusinessxml
6 Posts 2 Posters 24 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Drew Church
    wrote on last edited by
    #1

    Hello, I am trying to generate a unique value for a set of elements and place an element in each of the elements. They must have the same id but only the elements enclosed in an element like . So my XML Document looks like:

    22
    Test INC
    testdb
    Savings and Checking
    Escrow
    2016-21-03
    2016-21-15 23:52:33 EDT
    Maturity Notice Production
    1345
    345
    

    5432
    Primary owner
    Lynn
    Tanner
    5677
    Business phone
    (111)111-1111

      2456
        Personal email
        kkkkkkkkk@eirco423.net
      
      1135
        Home phone
        (111)111-1111
      
    
    5805
      Joint owner
      Ultra
      Tanner
    
    
    
      2456
      4070
      Residence
      43 Times Ping Two Rail Lane
      Thomas Co Commons Oreland
    
    
    1587
      Force pay
      4358
        0000000000
        E-statement only
        tay3456fgee@eircom.net
    
    J 1 Reply Last reply
    0
    • D Drew Church

      Hello, I am trying to generate a unique value for a set of elements and place an element in each of the elements. They must have the same id but only the elements enclosed in an element like . So my XML Document looks like:

      22
      Test INC
      testdb
      Savings and Checking
      Escrow
      2016-21-03
      2016-21-15 23:52:33 EDT
      Maturity Notice Production
      1345
      345
      

      5432
      Primary owner
      Lynn
      Tanner
      5677
      Business phone
      (111)111-1111

        2456
          Personal email
          kkkkkkkkk@eirco423.net
        
        1135
          Home phone
          (111)111-1111
        
      
      5805
        Joint owner
        Ultra
        Tanner
      
      
      
        2456
        4070
        Residence
        43 Times Ping Two Rail Lane
        Thomas Co Commons Oreland
      
      
      1587
        Force pay
        4358
          0000000000
          E-statement only
          tay3456fgee@eircom.net
      
      J Offline
      J Offline
      Jim Meadors
      wrote on last edited by
      #2

      Some thoughts as not sure what you are working with: Just use the ID of the parent element and don't bother to assign children ID's. If you are doing a LINQ query and target the parent element with the ID you are looking for your "result" will be the element along with its children which will have the "same ID" whether it is physically assigned or not. I also would guess that you are somehow programmatically creating the XML, adding to it occasionally or subtracting to update it. So, when you create a new element to add to your XML, include all children ID attributes at the time of creation. Hope that helps.

      <sig notetoself="think of a better signature"> <first>Jim</first> <last>Meadors</last> </sig>

      D 1 Reply Last reply
      0
      • J Jim Meadors

        Some thoughts as not sure what you are working with: Just use the ID of the parent element and don't bother to assign children ID's. If you are doing a LINQ query and target the parent element with the ID you are looking for your "result" will be the element along with its children which will have the "same ID" whether it is physically assigned or not. I also would guess that you are somehow programmatically creating the XML, adding to it occasionally or subtracting to update it. So, when you create a new element to add to your XML, include all children ID attributes at the time of creation. Hope that helps.

        <sig notetoself="think of a better signature"> <first>Jim</first> <last>Meadors</last> </sig>

        D Offline
        D Offline
        Drew Church
        wrote on last edited by
        #3

        What I want to do is import this into Access and query the tables. The problem is Access is picky about it and makes a table for everything so I need to be able to match the records. I have no control over creating the xml document but it is generated by a system.

        J 1 Reply Last reply
        0
        • D Drew Church

          What I want to do is import this into Access and query the tables. The problem is Access is picky about it and makes a table for everything so I need to be able to match the records. I have no control over creating the xml document but it is generated by a system.

          J Offline
          J Offline
          Jim Meadors
          wrote on last edited by
          #4

          OK, I'm guessing from that - you are not a developer? 2 ideas: Try importing into Excel. I've been able to work with XML files successfully there. Then you should be able to tweak it there. Easiest way would be to install Visual Studio latest free version and write a short query. P.S. The following code will do pretty much what you are saying in a Visual Basic Console Application:

          Dim myXMLFileLocation As String = "" 'INSERT YOUR FILE LOCATION
          Dim myXmlFile As XElement = XElement.Load(myXMLFileLocation)

              For Each ele In myXmlFile.Elements
                  For Each child In ele.Descendants
                      child.SetAttributeValue("type", ele.@type)
                  Next
              Next
              Console.WriteLine(myXmlFile.ToString)
              Console.ReadLine()
              myXmlFile.Save(myXMLFileLocation)
          

          <sig notetoself="think of a better signature"> <first>Jim</first> <last>Meadors</last> </sig>

          D 1 Reply Last reply
          0
          • J Jim Meadors

            OK, I'm guessing from that - you are not a developer? 2 ideas: Try importing into Excel. I've been able to work with XML files successfully there. Then you should be able to tweak it there. Easiest way would be to install Visual Studio latest free version and write a short query. P.S. The following code will do pretty much what you are saying in a Visual Basic Console Application:

            Dim myXMLFileLocation As String = "" 'INSERT YOUR FILE LOCATION
            Dim myXmlFile As XElement = XElement.Load(myXMLFileLocation)

                For Each ele In myXmlFile.Elements
                    For Each child In ele.Descendants
                        child.SetAttributeValue("type", ele.@type)
                    Next
                Next
                Console.WriteLine(myXmlFile.ToString)
                Console.ReadLine()
                myXmlFile.Save(myXMLFileLocation)
            

            <sig notetoself="think of a better signature"> <first>Jim</first> <last>Meadors</last> </sig>

            D Offline
            D Offline
            Drew Church
            wrote on last edited by
            #5

            Thank you Jim for your help but I think I solved the problem. I am a programmer and believe me I would have had this done in C# or VB sprinkle in some LINQ in less than an hour if I had my way. Loading it into Excel does work and is a valid solution, I just wanted to try to solve it with XSLT. I also need to automate this for everyday mail merges so Access is a nice easy solution for the company I work for. So below is my code:

                />
            

            />

            J 1 Reply Last reply
            0
            • D Drew Church

              Thank you Jim for your help but I think I solved the problem. I am a programmer and believe me I would have had this done in C# or VB sprinkle in some LINQ in less than an hour if I had my way. Loading it into Excel does work and is a valid solution, I just wanted to try to solve it with XSLT. I also need to automate this for everyday mail merges so Access is a nice easy solution for the company I work for. So below is my code:

                  />
              

              />

              J Offline
              J Offline
              Jim Meadors
              wrote on last edited by
              #6

              :thumbsup: Good on solving it. I didn't realize you were trying to solve it with XSLT :sigh: I didn't look as I thought it would be a "display" stylesheet...

              <sig notetoself="think of a better signature"> <first>Jim</first> <last>Meadors</last> </sig>

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups