Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't read xml files #22

Closed
ghost opened this issue Aug 3, 2015 · 18 comments
Closed

I can't read xml files #22

ghost opened this issue Aug 3, 2015 · 18 comments

Comments

@ghost
Copy link

ghost commented Aug 3, 2015

With this filter:

\usemodule[filter]

\defineexternalfilter
    [python]
    [filtercommand={python3 \externalfilterinputfile\space > \externalfilteroutputfile}, location=text]

and this code:

import os.path

with open('./b.txt', 'r') as f:
    r = f.read()
    print(len(r))

all is fine except when b.txt is an XML file. I get this

references      > start problematic references

references      > unknown >    1: [][]

references      > stop problematic references

What happens?

@adityam
Copy link
Owner

adityam commented Aug 4, 2015

Can you post a complete minimal working example with the XML file?

@ghost
Copy link
Author

ghost commented Aug 4, 2015

This is the contents of the b.xml. With other contents, I can't get any error:

<?xml version="1.0" standalone='yes'?>
<activitats>
  <activitat id="fitxes" tema="funcions" continguts="funció afí, dependència lineal, funcions a trossos">
    <presentacio tipus="tradicional" sintaxi="context" verbs="calcular">La fitxa blava i la fitxa vermella es mouen de la manera següent: la blava recorre les caselles d'una en una, mentre que la vermella les recorre de dues en dues però, després de cada moviment, s'espera un torn (figura~\in[]). Quina de les dues fitxes arribarà primer a la meta?
    </presentacio>
    <presentacio tipus="3-act" sintaxi="html" verbs="modelitzar">
     <actes>
       <u>vídeo fitxes</u>
       <dos></dos>
       <tres></tres>
     </actes>
    </presentacio>
  </activitat>
</activitats>

@adityam
Copy link
Owner

adityam commented Aug 4, 2015

I don't have python3, but with python 2.7.8, the following works fine:

\usemodule[filter]

\traceexternalfilters

\defineexternalfilter
    [python]
    [filtercommand={python \externalfilterinputfile\space > \externalfilteroutputfile}, location=text,
    cache=no]

\startbuffer[data]
<?xml version="1.0" standalone='yes'?>
<activitats>
  <activitat id="fitxes" tema="funcions" continguts="funció afí, dependència lineal, funcions a trossos">
    <presentacio tipus="tradicional" sintaxi="context" verbs="calcular">La fitxa blava i la fitxa vermella es mouen de la manera següent: la blava recorre les caselles d'una en una, mentre que la vermella les recorre de dues en dues però, després de cada moviment, s'espera un torn (figura~\in[]). Quina de les dues fitxes arribarà primer a la meta?
    </presentacio>
    <presentacio tipus="3-act" sintaxi="html" verbs="modelitzar">
     <actes>
       <u>vídeo fitxes</u>
       <dos></dos>
       <tres></tres>
     </actes>
    </presentacio>
  </activitat>
</activitats>
\stopbuffer

\savebuffer[list=data, file=b.xml, prefix=no]

\starttext
\startpython
import os.path

with open('./b.xml', 'r') as f:
    r = f.read()
    print(len(r))
\stoppython

\stoptext

@ghost
Copy link
Author

ghost commented Aug 4, 2015

Here not, with python2 and python3. I don't know why!

@adityam
Copy link
Owner

adityam commented Aug 4, 2015

Can you post the complete log file that you get when running my example?

On Aug 4, 2015, 12:15 PM, at 12:15 PM, Xavier notifications@github.com wrote:

Here not, with python2 and python3. I don't know why!


Reply to this email directly or view it on GitHub:
#22 (comment)

@ghost
Copy link
Author

ghost commented Aug 5, 2015

I push my contents here.

@adityam
Copy link
Owner

adityam commented Aug 5, 2015

In the first example (in your original bug report) you use print(len(r)) but in the second example (the one in your repo) you use print(r). So, the entire contents of your xml file are input as if you had literally typed them in your tex file. This means that you are compiling a tex file:

\starttext
..... \in[] ....
\stoptext

The error message:

references      > start problematic references

references      > unknown >    1: [][]

references      > stop problematic references

is telling you that <empty string> reference was not found.

@ghost
Copy link
Author

ghost commented Aug 8, 2015

With this

\startpython
from bs4 import BeautifulSoup
import json, os.path

with open('./dades/activitats.xml', 'r') as f:
    r = f.read()
    print(len(r))

#   soup = BeautifulSoup(r, "xml")
#
#   for a in soup.find_all("activitat", {'id': 'fitxes'}):
#       for p in a.find_all("presentacio"):
#           print(p.text)

\stoppython

I obtained the same result (empty string). What can I do=?

@adityam
Copy link
Owner

adityam commented Aug 8, 2015

  1. Remove the .tuc file and try again.
  2. If that does not work, remove the .tuc file and add
    \traceexternalfilters. This will not remove the \jobname-temp-*.tmp
    file. Open this file in an editor to see that it is written correctly. Run
    it through python to ensure that you are getting correct output.

On Sat, 8 Aug 2015, Xavier wrote:

With this

\startpython
from bs4 import BeautifulSoup
import json, os.path

with open('./dades/activitats.xml', 'r') as f:
  r = f.read()
  print(len(r))

# soup = BeautifulSoup(r, "xml")
#
# for a in soup.find_all("activitat", {'id': 'fitxes'}):
#     for p in a.find_all("presentacio"):
#         print(p.text)

\stoppython

I obtained the same result (empty string). What can I do=?


Reply to this email directly or view it on GitHub:
#22 (comment)

@ghost
Copy link
Author

ghost commented Aug 8, 2015

add \traceexternalfilters
where?

@adityam
Copy link
Owner

adityam commented Aug 8, 2015

See the example that I had posted.

On Aug 8, 2015, 10:35 AM, at 10:35 AM, Xavier notifications@github.com wrote:

add \traceexternalfilters
where?


Reply to this email directly or view it on GitHub:
#22 (comment)

@ghost
Copy link
Author

ghost commented Aug 8, 2015

I do not understand nothing.

@ghost
Copy link
Author

ghost commented Aug 9, 2015

Let's do simply example:

\startpython
import yaml

print("\startitemize")

with open('dades/accions.yaml', 'r') as f:
    r = yaml.load(f)
    print(r)
    for a in r:
        print("\item {0}".format(a))

print("\stopitemize")

\stoppython

This gives me blank string. How can I modify it for proper printing?

Thanks,

@adityam
Copy link
Owner

adityam commented Aug 9, 2015

Does this run correctly if you save the contents as a python file and compile it?

On Aug 9, 2015, 5:38 AM, at 5:38 AM, Xavier notifications@github.com wrote:

Let's do simply example:

\startpython
import yaml

print("\startitemize")

with open('dades/accions.yaml', 'r') as f:
r = yaml.load(f)
print(r)
for a in r:
print("\item {0}".format(a))

print("\stopitemize")

\stoppython

This gives me blank string. How can I modify it for proper printing?

Thanks,


Reply to this email directly or view it on GitHub:
#22 (comment)

@ghost
Copy link
Author

ghost commented Aug 9, 2015

Yes

@adityam
Copy link
Owner

adityam commented Aug 11, 2015

I don't know why this is not working. Can you create a complete and minimal example that does not work (similar to the one that I created in my comment above

@ghost
Copy link
Author

ghost commented Aug 13, 2015

I don't know too. With json it works

@ghost ghost closed this as completed Aug 13, 2015
@ghost
Copy link
Author

ghost commented Aug 18, 2015

Ruby does not do that. Perfect with ruby.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant