Case sesitivity in XML Tags and simplexml_load_file()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rainer Mohr

    Case sesitivity in XML Tags and simplexml_load_file()

    Hi,

    I´m having some problems with simplexml_load_ file() and cant find any
    sollution anywhere.

    Say, we have the following file:
    ---file.xml---
    <UNITS>Metric </UNITS>
    <UNITS>anothe r</UNITS>
    --------------

    The following code:
    -------------------
    $file = "file.xml";
    $xml = simplexml_load_ file($file) or die ("cant read file!");
    echo $xml->UNITS[0];
    -------------------

    Gives me back "Metric", which it should do.

    Now assume someone else uploads the following file:

    ---file.xml---
    <units>Metric </units>
    <units>anothe r</units>
    --------------

    The output is empty, because of the case-sensitivity.

    I cant influence how the user upload the files (upper or lower case in
    the tags), how can i solve this problem?

    I found xml_parser_set_ option($parser, XML_OPTION_CASE _FOLDING, true )
    but it wont affect simplexml_load_ file.

    Any suggestions?

    Thanks,
    Rainer
  • Malcolm Dew-Jones

    #2
    Re: Case sesitivity in XML Tags and simplexml_load_ file()

    Rainer Mohr (rainer.mohr@wi wi.uni-regensburg.de) wrote:
    : Hi,

    : I´m having some problems with simplexml_load_ file() and cant find any
    : sollution anywhere.

    : Say, we have the following file:
    : ---file.xml---
    : <UNITS>Metric </UNITS>
    : <UNITS>anothe r</UNITS>
    : --------------

    : The following code:
    : -------------------
    : $file = "file.xml";
    : $xml = simplexml_load_ file($file) or die ("cant read file!");
    : echo $xml->UNITS[0];
    : -------------------

    : Gives me back "Metric", which it should do.

    : Now assume someone else uploads the following file:

    : ---file.xml---
    : <units>Metric </units>
    : <units>anothe r</units>
    : --------------

    : The output is empty, because of the case-sensitivity.

    : I cant influence how the user upload the files (upper or lower case in
    : the tags), how can i solve this problem?

    Why not? The user needs to use the correct format for the data, and XML
    is quite definitively case sensitive.

    Define a DTD or schema and require the user to send data that is valid
    according to that.


    : I found xml_parser_set_ option($parser, XML_OPTION_CASE _FOLDING, true )
    : but it wont affect simplexml_load_ file.

    The XML_OPTION_CASE _FOLDING is a kludge to help with handling things like
    html, it should always be turned off for any regular xml parsing.


    --

    This space not for rent.

    Comment

    • Rainer Mohr

      #3
      Re: Case sesitivity in XML Tags and simplexml_load_ file()

      Hi Malcolm

      Malcolm Dew-Jones wrote:[color=blue]
      > Why not? The user needs to use the correct format for the data, and XML
      > is quite definitively case sensitive.[/color]

      I Know, but I cant influence what the users upload. Their xml data is
      created by different softwares and they dont even know what is in the
      files. They cant influence what the softwares do anyway.
      [color=blue]
      > : I found xml_parser_set_ option($parser, XML_OPTION_CASE _FOLDING, true )
      > : but it wont affect simplexml_load_ file.
      >
      > The XML_OPTION_CASE _FOLDING is a kludge to help with handling things like
      > html, it should always be turned off for any regular xml parsing.[/color]

      The data in the XML files is tranferred to a mysql database and then
      deleted. So I dont need the file afterwards. It would just be nice to be
      able to get the data into the database without asking the user to clean
      it up (for they wont).

      Therefore, can i influece simplexml_load_ file with the
      XML_OPTION_CASE _FOLDING in any way? If yes, then how?

      Thanks again,
      Rainer

      Comment

      • Oli Filth

        #4
        Re: Case sesitivity in XML Tags and simplexml_load_ file()

        Rainer Mohr said the following on 10/06/2005 19:30:[color=blue]
        > Hi Malcolm
        >
        > Malcolm Dew-Jones wrote:
        >[color=green]
        >>Why not? The user needs to use the correct format for the data, and XML
        >>is quite definitively case sensitive.[/color]
        >
        >
        > I Know, but I cant influence what the users upload. Their xml data is
        > created by different softwares and they dont even know what is in the
        > files. They cant influence what the softwares do anyway.[/color]

        Yes, but then that's their problem, not yours. If they upload invalid
        XML, then that's their fault.

        XML is supposed to be case-sensitive. If their software thinks
        otherwise, then their software is wrong.

        If you still want to work around this, then either use the event-driven
        XML functions which allow you to ignore case, or build your own XML
        parser (which isn't actually that hard).


        --
        Oli

        Comment

        Working...