Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SimpleXML: can I perform 'queries'?

    Hi,

    I'm looking into the possibilities of xml to store the data for a project I'm currently working on. I started out with SimpleXML, because it seems to me that I won't be doing any complicated stuff. However I can't figure out how to 'perform queries' on the xml-data with SimpleXML.

    First let me explain a little bit about my datamodel. I'm working on an invoice application. In invoices.xml I store all the invoices, like so (simplified for reference):

    Code:
    <invoices>
      <invoice id="01" client="1">
      <rule>
       <description>
        Description 1
       </description>
       <price>
        10
       </price>
      </rule>
      <rule>
       <description>
        Description 2
       </description>
       <price>
        20
       </price>
      </rule>
     </invoice>
    </invoices>
    As you can see, I set the client-id as an attribute of the invoice tag. This id obviously refers to a certain client, who's contact information is stored in another xml file (clients.php):

    Code:
    <clients>
     <client id="1">
      <name>
       Client name
      </name>
      <contact>
       Contact
      </contact>
      <address>
        Street
      </address>
     </client>
    </clients>
    Now I want to be able to connect the two files. When I view the complete invoice, I want to retrieve the appropriate contact information based on the client-id.

    How do I do such a thing? Is it possible to do this with SimpleXML or are the thing I want to do not that *simple*?

    Thanx in advance. -Michiel

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Looks like you're trying to implement a relational database in XML. Don't do that.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •