Xml file written in notepat - very bad idea

T

Tedy

Hi!

I have XML document that looks in shortcut like this:




< category >

< block >

< value > 5,234 </ value >

< possible result > 3,9219 </ possible result >

< possible result > 6,28365 </ possible result >

< possible result > 32.768 </ possible result >

</ block >

</ category >

< category >

< block >

< value > 23 </ value >

< possible result > 4345 </ possible result >

< possible result > 637.9 </ possible result >

</ block >

</ category >

< category >

< block >

< value > 2.8 </ value >

< like for > 5,234 </ like for >

</ block >

</ category >
The database is growing and I need tool to manage this.

Is there any programs that helps manage such XML data base. Especially I am
interested in:

Sorting categories blocks by the value in < value > tag, checking syntax.



Thanks for all help

Tedy
 
M

Magnus Henriksson

Tedy said:
Hi!

I have XML document that looks in shortcut like this:




< category >

< block >

< value > 5,234 </ value >

< possible result > 3,9219 </ possible result >

< possible result > 6,28365 </ possible result >

< possible result > 32.768 </ possible result >

</ block >

</ category >

< category >

< block >

< value > 23 </ value >

< possible result > 4345 </ possible result >

< possible result > 637.9 </ possible result >

</ block >

</ category >

< category >

< block >

< value > 2.8 </ value >

< like for > 5,234 </ like for >

</ block >

</ category >
The database is growing and I need tool to manage this.

Is there any programs that helps manage such XML data base. Especially I am
interested in:

Sorting categories blocks by the value in < value > tag, checking syntax.

Your first problem would be that the example above is not valid XML:

- Whitespace is not allowed between '<' and the element name in start tags.
See http://www.w3.org/TR/REC-xml/#NT-STag

- Whitespace is not allowed between '</' and the element name in end tags.
See http://www.w3.org/TR/REC-xml/#NT-ETag

- Element names may not contain whitespace.
See http://www.w3.org/TR/REC-xml/#NT-Name

- The document may only have one root element.
See http://www.w3.org/TR/REC-xml/#NT-document


If that is fixed (in this example, I've used hyphens instead of space and
added a 'categories' root element, but you can use whatever you like. I've
also trimmed element content from some whitespace), we get:

<categories>
<category>
<block>
<value>5,234</value>
<possible-result>3,9219</possible-result>
<possible-result>6,28365</possible-result>
<possible-result>32.768</possible-result>
</block>
</category>
<category>
<block>
<value>23</value>
<possible-result>4345</possible-result>
<possible-result>637.9</possible-result>
</block>
</category>
<category>
<block>
<value>2.8</value>
<like-for>5,234</like-for>
</block>
</category>
</categories>

When this is done, we can manipulate it with, for example XSLT, to filter
and sort the information.

In XML, there are at least two levels of syntax checking: a document can be
well formed, or it can be well-formed and valid. The 'fixed' document above
is well-formed as defined in the XML Recommendation
(http://www.w3.org/TR/REC-xml/#dt-wellformed). To be valid the document need
to refer to a DTD and comply with the constraints it expresses
(http://www.w3.org/TR/REC-xml/#dt-valid).

(I've never thought about this, but this means that other brands of schemas,
such as W3C XML Schemas, RELAX NG, and Schematron, has nothing to do with
whether a document is valid or not. Only documents that conform to a DTD can
be valid from an XML 1.0 perspective. Which means that I need to sharpen up
my terminology.)


// Magnus
 
M

Mukul Gandhi

Hi Tedy,
You can do the sorting using XSLT.

Given this XML file -
<?xml version="1.0"?>
<categories>
<category>
<block>
<value>5234</value>
<possibleresult>39219</possibleresult>
<possibleresult>628365</possibleresult>
<possibleresult>32.768</possibleresult>
</block>
</category >
<category>
<block>
<value>23</value>
<possibleresult>4345</possibleresult>
<possibleresult>637.9</possibleresult>
</block>
</category>
<category>
<block>
<value>2.8</value>
<likefor>5234</likefor>
</block>
</category>
</categories>

The following XSLT stylesheet does sorting -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="xml" indent="yes" />

<xsl:template match="/categories">
<categories>
<xsl:for-each select="category">
<xsl:sort select="block/value" data-type="number" />
<xsl:copy-of select="." />
</xsl:for-each>
</categories>
</xsl:template>

</xsl:stylesheet>

To manage your XML project, you can use a tool like XML Spy, Stylus
Studio etc.

Regards,
Mukul
 
C

Chris Lovett

Note that you can also easily load this XML into a DataSet and bind it to a
WinForms DataGrid and build you own little "GUI Editor" for editing your
data - or you can bind it to an ASP.NET DataGrid for adding rows and editing
valies in an HTML page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top