Re: [xslt] parsing xml-files



On Mon, May 14, 2001 at 12:43:25PM +0200, Kris Vloeberghs wrote:
> When I looked at the documentation in the W3 pages, it seemed that using a
> namespace prefix is not obligated.  It even seems so that when you define a
> namespace in a node, all childnodes use this namespace, unless you declare a
> new one, or use a prefix for a node.  This means a xml like the following is
> well formed:
> 
> <?xml version='1.0' encoding='utf-8'?>
> <record xmlns="http://namespace_1/">
>   <data>
>     <person xmlns="http://namespace_2/">
>       <name>vloeberghs</name>
>       <firstname>kris</firstname>
>     </person>
>   </data>
> </record>

  yes,

> The nodes <record> en <data> should make use of namespace_1, the nodes
> <person>, <name> and <firstname> should make use of namespace_2.  According
> to what W3 says, this is a wellformed XML-doc.

  yes

> My question is the following:
> Howcome I'm unable to parse this document withoud adding prefixes

  Wrong it parses with libxml2 :

orchis:~/XML -> cat tst.xml
<?xml version='1.0' encoding='utf-8'?>
<record xmlns="http://namespace_1/">
  <data>
    <person xmlns="http://namespace_2/">
      <name>vloeberghs</name>
      <firstname>kris</firstname>
    </person>
  </data>
</record>

orchis:~/XML -> ./xmllint tst.xml
tst.xml:2: warning: nmlns: http://namespace_1/ not a valid URI
<record xmlns="http://namespace_1/">
                                   ^
tst.xml:4: warning: nmlns: http://namespace_2/ not a valid URI
    <person xmlns="http://namespace_2/">
                                       ^
<?xml version="1.0" encoding="utf-8"?>
<record xmlns="http://namespace_1/">
  <data>
    <person xmlns="http://namespace_2/">
      <name>vloeberghs</name>
      <firstname>kris</firstname>
    </person>
  </data>
</record>
orchis:~/XML -> 


  You get a result tree but you also get warning and for a good reason 
Just read the warning emitted by the tools !!!


> (like the
> following)?
> 
> <?xml version='1.0' encoding='utf-8'?>
> <xsi:record xmlns="http://namespace_1/">
>   <xsi:data>
>     <person pers:xmlns="http://namespace_2/">
>       <pers:name>vloeberghs</pers:name>
>       <pers:firstname>kris</pers:firstname>
>     </pers:person>
>   </xsi:data>
> </xsi:record>

  Wrong AGAIN !!!!

orchis:~/XML -> cat tst.xml
<?xml version='1.0' encoding='utf-8'?>
<xsi:record xmlns="http://namespace_1/">
  <xsi:data>
    <person pers:xmlns="http://namespace_2/">
      <pers:name>vloeberghs</pers:name>
      <pers:firstname>kris</pers:firstname>
    </pers:person>
  </xsi:data>
</xsi:record>
orchis:~/XML -> ./xmllint tst.xml
tst.xml:2: warning: nmlns: http://namespace_1/ not a valid URI
<xsi:record xmlns="http://namespace_1/">
                                       ^
tst.xml:2: warning: Namespace prefix xsi is not defined
<xsi:record xmlns="http://namespace_1/">
                                       ^
tst.xml:3: warning: Namespace prefix xsi is not defined
  <xsi:data>
           ^
tst.xml:5: warning: Namespace prefix pers is not defined
      <pers:name>vloeberghs</pers:name>
                ^
tst.xml:6: warning: Namespace prefix pers is not defined
      <pers:firstname>kris</pers:firstname>
                     ^
tst.xml:7: error: Opening and ending tag mismatch: person and pers:person
    </pers:person>
                 ^
orchis:~/XML -> 


> The actual problem is that my XML-doc comes from the server looking like my

  If your server outputs incorrect URIs for namespaces, well either
ignore the warning or fix your server !

But PLEASE, make the minimal research on your own before posting 
to this list things which are not related to libxslt. I have enough work
dealing with messages related to libxml and libxslt, I CANNOT do your
homework, I'm sorry ! Looking at your organisation homepage you are a
commercial entity, I see no reason to provide you with free consulting.
Maybe someone from this list can help you on the matter. You can also
look at xml-dev or xslt-dev (any search engine will point you to those
mainling lists), for general help on XML and XSLT matters.

Daniel

-- 
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard@redhat.com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]