pp22 Posted September 25, 2006 Share Posted September 25, 2006 I wonder if anyone could kindly help to parse the following xml file? Really need help with this. xml file:----------------------------------------------------------------- <Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication></Document> <Document><publication><property name="PU" value="b"></property><property name="PD" value="bb"></property><property name="PG" value="bbb"></property><property name="HD" value="bbbbb"></property><property name="TX" value="bbbbbbbbb"></property></publication></Document>-------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
boen_robot Posted September 25, 2006 Share Posted September 25, 2006 So what exactly is the problem here? Other then the fact that you have two root elements I mean.If your problem is exactly that, then just try: <Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication><publication><property name="PU" value="b"></property><property name="PD" value="bb"></property><property name="PG" value="bbb"></property><property name="HD" value="bbbbb"></property><property name="TX" value="bbbbbbbbb"></property></publication></Document> Link to comment Share on other sites More sharing options...
Skemcin Posted September 25, 2006 Share Posted September 25, 2006 What are you using?php, asp, cold fusion, xslt, sql?We need a little more information in order to provide any sort of assistance. Link to comment Share on other sites More sharing options...
pp22 Posted September 26, 2006 Author Share Posted September 26, 2006 I intend to attach the xml file in a ASP or HTML page. Could you kindly help?xml file:-----------------------------------------------------------------<Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication></Document><Document><publication><property name="PU" value="b"></property><property name="PD" value="bb"></property><property name="PG" value="bbb"></property><property name="HD" value="bbbbb"></property><property name="TX" value="bbbbbbbbb"></property></publication></Document>-------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
pp22 Posted September 26, 2006 Author Share Posted September 26, 2006 I really new to scripting, cant write a script parsing the two root elements. Also I cant make changes to the format or configuration of the xml file bcos the file is on their web server which I need to link onto my site. Is there any still simple script or solution to parse everything in the xml file? Really confused by this 2 root element, need help? Many thanks in advance.<Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication></Document><Document><publication><property name="PU" value="b"></property><property name="PD" value="bb"></property><property name="PG" value="bbb"></property><property name="HD" value="bbbbb"></property><property name="TX" value="bbbbbbbbb"></property></publication></Document> Link to comment Share on other sites More sharing options...
boen_robot Posted September 27, 2006 Share Posted September 27, 2006 Normally, a single XML document may look like this: <?xml version="1.0"?><Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication><publication><property name="PU" value="b"></property><property name="PD" value="bb"></property><property name="PG" value="bbb"></property><property name="HD" value="bbbbb"></property><property name="TX" value="bbbbbbbbb"></property></publication></Document> or this: <?xml version="1.0"?><Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication></Document> If all of your code above is the complete content of an XML file, then the complete contents with the XML prolog (the top line) would be like: <?xml version="1.0"?><Document><publication><property name="PU" value="aaaaa"></property><property name="PD" value="aaaaaaa"></property><property name="PG" value="aaaaaa"></property><property name="HD" value="aaaaaaaa"></property><property name="TX" value="aaaaaaa"></property></publication></Document><Document><publication><property name="PU" value="b"></property><property name="PD" value="bb"></property><property name="PG" value="bbb"></property><property name="HD" value="bbbbb"></property><property name="TX" value="bbbbbbbbb"></property></publication></Document> If that is so, then any attempt to parse this XML with whatever language would fail, because that XML document is not well formed or in other words, it doesn't follow the XML rules. There can only be one element that holds others within it. That element is called a root element. In all of the previous examples <Document> is the root element. However, the last example has two <Document> elements, not one.You may have one <Document> nested inside another one, but you can never have two <Document> elements as the root element.Another thing you must understand is that XML files aren't just "attached". They need to be read (parsed) by some language (it's not a fixed one) and that language then uses the data for something (showing it for example). That "something" is also defined by the other language itself.Read the XPath tutorial and the XSLT tutorial. Part of the XSLT tutorial also shows how to execute an XSLT transformation inside an ASP page. Alternatives in other languages are also avaiable (I'm just saying...). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now