Jump to content

XML structure


ohayo85

Recommended Posts

Hi, I'm brand new in XML and currently i using XML and XSLT for my project in college.I got a problem here.My xml file structure look like this:

<?xml version="1.0" encoding="UTF-8"?><CompanyA>  <door>DATA</door>  <glass>DATA</glass>  <tile>DATA</tile></CompanyA><CompanyB>  <door>DATA</door>  <window>DATA</window>  <glass>DATA</glass></CompanyB><CompanyC>  <glass>DATA</glass>  <tile>DATA</tile>  <lightbulb>DATA</lightbulb></CompanyC>..continue

Basically i got different data from different company. Problem now is .. if i would like to display the glass products from different company, how can i select the companies which have the door <tag> and display it out ?I'm stuck here :)Any help will be greatly appreciated it...

Link to comment
Share on other sites

Hmm.. Problem again. :) If i would like to enter data into xml fileLet say i got an xml file:<?xml version="1.0" encoding="UTF-8"?><companyName> <company name="A"> <door>DATA</door> <glass>DATA</glass> <tile>DATA</tile> </company></companyName>I would like to enter particular data from HTML form into XML file.for example i would like to enter <company name="B"> with <glass>DATA</glass> , <lightbulb>DATA</lightbulb>into the existing XML file. Any suggestion on doing it?

Link to comment
Share on other sites

With any S3L you're comfortable with. For example - PHP.In PHP(5!!!), you can use DOM for that. If you're experienced with JavaScript's DOM, learning PHP's one is a matter of one to ten minutes. Pretty much, the only thing new there is the DOMDocument::save() method which saves the tree to a file - something not possible with JavaScript for security reasons. If this is the first time you're using a DOM aware language (any one), then it might take longer.In summary - with DOMNode::appendChild() you insert an element at the bottom of the child nodes of a certain node. For example, if you select the companyName element, appendChild() will append the targeted element right before the </companyName> tag.DOMDocument::create*() and DOMDocument::create*NS() are used to create various nodes ("*" representing whatever node type you want to create) that you can then insert with DOMNode::appendChild(). The difference with the ones ending with "NS" is that they also allow you to specify a namespace for the new node, but if you don't need that, use the ones without NS instead.Besides using DOMDocument::createAttribute(), you can also create or edit attributes with DOMElement::setAttribute() which I think is a more elegant way anyway.Text contents can be edited by either adjusting the DOMNode::nodeValue property of the node, or (in more complicated cases like elements that contain both text and elements) creating and appending text nodes.

Link to comment
Share on other sites

Thanks to you for replying. Actually i read up all the tutorial of DOM and PhP(5) and quite understand about it.Perhaps sound quite noob to you all but i need get some advices from you. Lets say i have an XML file which stored products data of the companyA and enable suppliers to upload their XML file through browsers into the company servers(is that possible?). I would like to ask, is that limitation size of the XML file? Is it seperate few XML file better or single XML file is sufficient enough? Make it more simple:Option1:Should i put everything data into single XML file like product.xml is enough?or Option2:Contain few of the xml file such as SupplierA.xml belong to supplier A, SupplierB.xml belong to supplier B and etc....If is option2, lets say i provide an friendly interface for suppliers to enable to key in the new product, modify or delete but how to identify that interface is belongs to supplier A in supplierA.xml?Situation:Supplier A would like to update their product information through browser and log in as supplier member and update products but how to identify that is only supplierA.xml?(is that possible?). Because every supplier can add,modify or delete their own xml file only and cannot access other suppliers xml(is that belong to security features?) With this, the companyA can always browse the latest product from their suppliers through companyA own website instead of getting the hardcopy catalogue from them. Perhaps this is only the structure of storing but i never did any system before so i would like to get some advice or opinion. Any suggestion or advices will highly appreciated... :)

Link to comment
Share on other sites

It depends a lot on the whole structure of the application, and more importantly - how do you parse it.If you use XMLReader for the sake of low memory consumption, it's easier with one whole file. However, editing this file gets a little more harder, because if you use DOM to edit it, you end up consuming a ton of memory. Once I read something like 2MB XML being equal to 12MB of RAM consumed. Imagine if your XML reaches 1GB (I've actually heared of XMLs being 2GBs large).Having many small XML files is fast and an easy to do thing when dealing with one or two small XMLs at a time. And there's an overhead every time you load another XML with DOM because it gets turned into a DOM tree.For your case, I'd say using an XML file for each company is better. Companies can log in with log in screens that are based on PHP sessions (there are many tutorials on the net about that). Once logged, you can simply use their username to determine the XML file you need to append to.Another, more secure I'd say, but A LOT less user friendly way is with HTTP authentication (ideally sent over SSL if you can afford that). Sessions expire immediatly after the browser closes (unless there are special settings in the browser), there's an ugly screen appearing before anything else is shown... but it's impossible for a session to be stolen, and considerations for whether the right user was logged in are left out of the PHP. Only traffic could be spoofed (where SSL comes in), but that possibility is present with PHP sessions too.

Link to comment
Share on other sites

Thanks for the advices. And i still got question would like to ask. Sorry for troublesome :) Let's say i got multiple XML file like each supplier each XML file like i mentioned it before, but if i would like to store it each category of each type of the product(like door.xml, motor.xml, car.xml) For example:Company X contain 5 XML file, ( A,B,C,D,E )Company Y contain 3 XML file, (A,B,F)Company Z contain 4 XML file (A,B,C,W) Basically X , Y and Z supply the same product in file A and B but different value and price.Is that possible to retrieve data from each B file? Let say i would like to retrieve Xproduct from B file of all company, is it i have to use XQuery in order to retrieve the data? If not, what else can i do in order to retrieve the all data but different company? i search few days but can't get any idea of getting it. >.<~ (perhaps i lack of understanding).Again, thanks for advance.any advices or help will be greatly appreciated... :)

Link to comment
Share on other sites

This is starting to sound more like a job for SQL than XML. XML stores data in hierarical form (A,B,C,D and E belong to X; A,B and F belong to Y), and SQL databases store it in relational form (A and B belong to X,Y and Z and vise versa; C belongs to X and Z and vise versa).While it's possible to make XML behave in a relational form, doing so usually has great performance implications. W3C is working on SPARQL, which will allow languages like PHP to query RDF files in relational form. RDF itself can be presented in XML, or it may not be, which is why SPARQL is needed, instead of XPath. But besides that, it's also going to try to overcome the performance barrier, since the SPARQL parser is going to be doing the association of one data with another the way SQL does it.Until SPARQL is actually implemented as a PECL extension and good tutorials for it arrive, you should avoid using XML in a relational form. If it's just that you're comfortable using XML, you may try PEAR packages like Query2XML to generate XML files from SQL queries. By using XSLT, you can then process the result set to XHTML or whatever else is needed, ensuring better code portability that what using plain SQL would give you.BTW, if you decide to use SQL, I suggest you use the MySQLi extension, instead of the MySQL extension. It's newer and less supported (i.e. less hosts have it on), but it's faster and more secure. Unless your host can't enable it, use MySQLi.

Link to comment
Share on other sites

:mellow: oh man~ Currently i doing this for my final assignment in college. I'm abit confusing getting the concept.Supposely i have to do it with RDF/XML but because i'm newbie in this framework. So i would like start do it with XML and XSLT form first. Then only try to enhance RDF into XML(sound like semantic web but i'm still confuse about it). But now i'm stucked in structure of storing the XML and retrieving of it (i would like to get the concept first). :) Then any suggestion or opinion which can help to do structure of the XML?i have condition which i mentioned before, Assume:- i got many suppliers which supply products to us and hope can store their product in XML but in which way i should store of their product? What i did is stored each supplier in each XML file but because of the too many category, that's why i break into more XML file like supplierA got 10 XML file(like door.xml, tile.xml, car.xml and etc). Is it good enough if i dumb all into 1 XML file for each company? (any suggestion or other way of doing it?)(assume i have 10 - 50 supplier)- Admin enable to retrieve the data from all suppliers on particular product. Lets say admin would to see particular product from all supplier to make comparison. I know sound like doing relational in SQL but what my lecturer want me to do is the system enable to retrieve data from XML in way i mentioned it above. (Sound like doing semantic web? I think so) Argh~! i know is hard which have to use it RDF and SPARQL but i had doing research on it for a month but still not really understand about it. Perhaps i lack of understanding but this final assignment is important for me. :wub: Thanks to Mr Boen_Robot reply and helping me so much :)Any suggestion or help will really really appreciated it.Thanks for advance.ohayo85.
Link to comment
Share on other sites

Right now, and possibly long after your final assignment is over, the problem with RDF and SPARQL is first and foremost, the lack of good implementations. That is the top "no no" for discouraging you to even think of trying RDF and SPARQL. The lack of understanding can be defeated with some trial&error if you could only experiment with it, but because of lacking implementations, you can't.Unless this final assignment requires you to use XML for this, I suggest you try using MySQLi or better yet - PEAR's MDB2.If it requires you to use XML as a data storage, I guess you're stuck with creating a very inefficient application.Someone needs to suffer at some point, and it's likely the admin would be the one. If you store the different files based on company and product categories, when the admin wants to search for a product, it must search in every XML file to see if the targeted product exists. Even if the category of the product is known in advance, the file of every company for that category must still be parsed and queried separately. If you have 50 companies, this makes a minimum of 50 invocations of the parser and XPath engine (provided you use XPath for the querying), and that is only if the category is known. Multiply that by the amount of categories in each company (i.e. the total amount of XML files), and you get even bigger numbers for the case where the category is unknown.And as said already, having one file would mean one invocation, but far bigger memory consumption if DOM is used. And XMLReader, which avoids the memory consumption makes it impossible to edit the file. A duo of XMLReader (reading the XML file) and XMLWriter (writing a new file based on what XMLReader reads, at some point adding/editing what's needed) used with a single big file is a possible solution, but it's so hard to make and maintain (i.e. it's not flexible at all), not to mention unportable (since you're heavily dependant on those two PHP APIs), that it's simply not worth it.And as for using XMLReader to read many small XML files... I don't think it's worth it. While it keeps memory low, querying the data is hard, and the actual processing time may be reduced due to the constant calls of XMLReader::read(). I'm not sure about that last one though, so it may actually be the thing you need to use. Still, it's harder to use and navigate within than DOM.Bottom line - use MySQLi for relational data like that if you can. Everything else is harder to get right on the large scale.

Link to comment
Share on other sites

Perhaps i have to go on it. Anyways, i would like to ask about SPARQL and hope you could tell me :) ( if you know, but if not then never mind )Any extension for SPARQL ? i know quite pretty much about the syntax but i couldn't test the query. Is it i have to use Jena API in order to run test it? Sorry sound like a noob. What form i should write in SPARQL? like xml is in extension .xml and rdf is in extension .rdf....Any help will greatly appreciate it..and Special thanks to boen_robot for helping so much.. :) Again thanks for advance.ohayo85

Link to comment
Share on other sites

SPARQL, like SQL is written directly within the PHP file or whatever other environment you use to make the query. Some environments may allow you to save SPARQL files with some extensions, but they don't care about it really.Jena is one way to run SPARQL I suppose... but are you running JAVA? Jena is for JAVA. For PHP, the only implementation I have found is ARC2, but I have no idea how to use it yet, as I don't know any SPARQL... I just (think I) know what it's used for. Good luck to you using it.To make things even worse, it may turn out that you also need OWL to tell the SPARQL engine exactly what is related to what, so that SPARQL can do the association. Something which I don't see ARC2 supporing right now.And btw, RDF is not always in RDF files. RDF decribes only the "triplets" idea. That you describe a "resource" (1) with a "properies" (2) each of which has a "value" (3). RDF files with XML syntax are only one way to store RDF data. ARC2 however also supports (ot at least seem to support) extracting RDF from other RDF representations like RDF/JSON, Turle and RDFa.

Link to comment
Share on other sites

hello, boen_robot...I would like to ask you, do you know anything about User Interface Language (XUL)? If no.. then never mind.If yes, do you know how to load the RDF datasource? sound like noob right? :) Basically i know have to usevar RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);var ds=RDF.GetDataSource("file:///C:\Documents and Settings\XUL\animals.rdf");but seems not loading.. :) Anyone can help?Could you provide any examples ? Thanks in advance.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...