XML Python parsing for creating database











up vote
1
down vote

favorite












I'm trying to create a database using python on my xml file. I'm closed to the output I wish.



First, here is my Xml :



<?xml version="1.0" encoding="UTF-8"?>
-<SoccerFeed TimeStamp="20180518T155346+0100">
-<SoccerDocument uID="f920535" detail_id="1" Type="Result">
+<Competition uID="c24">
-<MatchData>
+<MatchInfo TimeStamp="20170805T180614+0100" Period="FullTime"
MatchType="Regular">
-<MatchOfficial uID="o41564">
+<OfficialData>
+<OfficialName>
</MatchOfficial>
+<AssistantOfficials>
<Stat Type="match_time">95</Stat>
<Stat Type="first_half_start">20170805T161515+0100</Stat>
<Stat Type="first_half_time">46</Stat>
<Stat Type="first_half_stop">20170805T170023+0100</Stat>
<Stat Type="second_half_start">20170805T171702+0100</Stat>
<Stat Type="second_half_time">50</Stat>
<Stat Type="second_half_stop">20170805T180614+0100</Stat>
-<TeamData TeamRef="t149" Side="Home" Score="2">
-<Goal TimeStamp="20170805T165633+0100" uID="g149-1" Type="Goal"
Period="FirstHalf" Time="42" Sec="18" PlayerRef="p40720" Min="41"
EventNumber="1421" EventID="1618948311">
<Assist PlayerRef="p15780">p15780</Assist>
</Goal>
+<Goal TimeStamp="20170805T175201+0100" uID="g149-2" Type="Goal"
Period="SecondHalf" Time="80" Sec="58" PlayerRef="p54782" Min="79"
EventNumber="2802" EventID="1632402633">
-<PlayerLineUp>
-<MatchPlayer PlayerRef="p84182" Status="Start" ShirtNumber="16"
Position="Goalkeeper">
<Stat Type="leftside_pass">7</Stat>
<Stat Type="accurate_keeper_sweeper">1</Stat>
<Stat Type="accurate_pass">30</Stat>
<Stat Type="rightside_pass">11</Stat>
<Stat Type="attempts_conceded_ibox">3</Stat>
<Stat Type="touches">44</Stat>
<Stat Type="total_fwd_zone_pass">2</Stat>
<Stat Type="keeper_pick_up">6</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p116406" Status="Start" ShirtNumber="5"
Position="Defender">
<Stat Type="duel_lost">2</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">34</Stat>
<Stat Type="att_rf_total">2</Stat>
<Stat Type="att_bx_right">1</Stat>
<Stat Type="accurate_pass">69</Stat>
<Stat Type="att_miss_left">1</Stat>
<Stat Type="total_final_third_passes">2</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p15780" Status="Start" ShirtNumber="32"
Position="Defender">
<Stat Type="total_through_ball">1</Stat>
<Stat Type="duel_lost">4</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">46</Stat>
<Stat Type="dispossessed">1</Stat>
<Stat Type="accurate_cross">2</Stat>
<Stat Type="att_rf_total">1</Stat>
</MatchPlayer>


I would like to get the Id of the player ("PlayerRef"), his "ShirtNumber", his "Position", the "Type of the statistic" and the "Statistic" itself.



For now, what I have done is close to the output expected, but I still got an error that I can't fix.
Here my python code :



import os
from xml.etree import ElementTree

file_name="C:/Users/Hp/Desktop/BYG/PSG-Amiens.xml"
full_file=os.path.abspath(os.path.join('BYG',file_name))
dom=ElementTree.parse(full_file)

Stats=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer/Stat')


for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))


When I run this code, it compiles all the type of statistics and the statistics of every players for just one player when it should be just the type of statistics of the player concerned and his statistics, not the one from all others players.



To be more clear, For the player 1 I should get just the ID, the ShirtNumber,
the Position, All the type of Statistics and the statistics for the player 1.



But instead I get his ID, ShirtNumber,Position and All the type of Statistics and the statistics present in my xml file.



How could I fix that?



I hope I have been clear enough, don't hesitate to ask me more precisions if I haven't been clear enough



Thanks in advance










share|improve this question






















  • It looks like you are iterating through all 'MatchPlayer/Stat' elements. You should narrow your search to only get the stats of the player you are working with.
    – boonwj
    Nov 11 at 11:02










  • Unrelated, but do those + and - really appear in your XML?
    – usr2564301
    Nov 11 at 12:02










  • @usr2564301 It appears on my XML interpreter, but not on a url file
    – Jordi
    Nov 11 at 14:23















up vote
1
down vote

favorite












I'm trying to create a database using python on my xml file. I'm closed to the output I wish.



First, here is my Xml :



<?xml version="1.0" encoding="UTF-8"?>
-<SoccerFeed TimeStamp="20180518T155346+0100">
-<SoccerDocument uID="f920535" detail_id="1" Type="Result">
+<Competition uID="c24">
-<MatchData>
+<MatchInfo TimeStamp="20170805T180614+0100" Period="FullTime"
MatchType="Regular">
-<MatchOfficial uID="o41564">
+<OfficialData>
+<OfficialName>
</MatchOfficial>
+<AssistantOfficials>
<Stat Type="match_time">95</Stat>
<Stat Type="first_half_start">20170805T161515+0100</Stat>
<Stat Type="first_half_time">46</Stat>
<Stat Type="first_half_stop">20170805T170023+0100</Stat>
<Stat Type="second_half_start">20170805T171702+0100</Stat>
<Stat Type="second_half_time">50</Stat>
<Stat Type="second_half_stop">20170805T180614+0100</Stat>
-<TeamData TeamRef="t149" Side="Home" Score="2">
-<Goal TimeStamp="20170805T165633+0100" uID="g149-1" Type="Goal"
Period="FirstHalf" Time="42" Sec="18" PlayerRef="p40720" Min="41"
EventNumber="1421" EventID="1618948311">
<Assist PlayerRef="p15780">p15780</Assist>
</Goal>
+<Goal TimeStamp="20170805T175201+0100" uID="g149-2" Type="Goal"
Period="SecondHalf" Time="80" Sec="58" PlayerRef="p54782" Min="79"
EventNumber="2802" EventID="1632402633">
-<PlayerLineUp>
-<MatchPlayer PlayerRef="p84182" Status="Start" ShirtNumber="16"
Position="Goalkeeper">
<Stat Type="leftside_pass">7</Stat>
<Stat Type="accurate_keeper_sweeper">1</Stat>
<Stat Type="accurate_pass">30</Stat>
<Stat Type="rightside_pass">11</Stat>
<Stat Type="attempts_conceded_ibox">3</Stat>
<Stat Type="touches">44</Stat>
<Stat Type="total_fwd_zone_pass">2</Stat>
<Stat Type="keeper_pick_up">6</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p116406" Status="Start" ShirtNumber="5"
Position="Defender">
<Stat Type="duel_lost">2</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">34</Stat>
<Stat Type="att_rf_total">2</Stat>
<Stat Type="att_bx_right">1</Stat>
<Stat Type="accurate_pass">69</Stat>
<Stat Type="att_miss_left">1</Stat>
<Stat Type="total_final_third_passes">2</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p15780" Status="Start" ShirtNumber="32"
Position="Defender">
<Stat Type="total_through_ball">1</Stat>
<Stat Type="duel_lost">4</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">46</Stat>
<Stat Type="dispossessed">1</Stat>
<Stat Type="accurate_cross">2</Stat>
<Stat Type="att_rf_total">1</Stat>
</MatchPlayer>


I would like to get the Id of the player ("PlayerRef"), his "ShirtNumber", his "Position", the "Type of the statistic" and the "Statistic" itself.



For now, what I have done is close to the output expected, but I still got an error that I can't fix.
Here my python code :



import os
from xml.etree import ElementTree

file_name="C:/Users/Hp/Desktop/BYG/PSG-Amiens.xml"
full_file=os.path.abspath(os.path.join('BYG',file_name))
dom=ElementTree.parse(full_file)

Stats=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer/Stat')


for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))


When I run this code, it compiles all the type of statistics and the statistics of every players for just one player when it should be just the type of statistics of the player concerned and his statistics, not the one from all others players.



To be more clear, For the player 1 I should get just the ID, the ShirtNumber,
the Position, All the type of Statistics and the statistics for the player 1.



But instead I get his ID, ShirtNumber,Position and All the type of Statistics and the statistics present in my xml file.



How could I fix that?



I hope I have been clear enough, don't hesitate to ask me more precisions if I haven't been clear enough



Thanks in advance










share|improve this question






















  • It looks like you are iterating through all 'MatchPlayer/Stat' elements. You should narrow your search to only get the stats of the player you are working with.
    – boonwj
    Nov 11 at 11:02










  • Unrelated, but do those + and - really appear in your XML?
    – usr2564301
    Nov 11 at 12:02










  • @usr2564301 It appears on my XML interpreter, but not on a url file
    – Jordi
    Nov 11 at 14:23













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to create a database using python on my xml file. I'm closed to the output I wish.



First, here is my Xml :



<?xml version="1.0" encoding="UTF-8"?>
-<SoccerFeed TimeStamp="20180518T155346+0100">
-<SoccerDocument uID="f920535" detail_id="1" Type="Result">
+<Competition uID="c24">
-<MatchData>
+<MatchInfo TimeStamp="20170805T180614+0100" Period="FullTime"
MatchType="Regular">
-<MatchOfficial uID="o41564">
+<OfficialData>
+<OfficialName>
</MatchOfficial>
+<AssistantOfficials>
<Stat Type="match_time">95</Stat>
<Stat Type="first_half_start">20170805T161515+0100</Stat>
<Stat Type="first_half_time">46</Stat>
<Stat Type="first_half_stop">20170805T170023+0100</Stat>
<Stat Type="second_half_start">20170805T171702+0100</Stat>
<Stat Type="second_half_time">50</Stat>
<Stat Type="second_half_stop">20170805T180614+0100</Stat>
-<TeamData TeamRef="t149" Side="Home" Score="2">
-<Goal TimeStamp="20170805T165633+0100" uID="g149-1" Type="Goal"
Period="FirstHalf" Time="42" Sec="18" PlayerRef="p40720" Min="41"
EventNumber="1421" EventID="1618948311">
<Assist PlayerRef="p15780">p15780</Assist>
</Goal>
+<Goal TimeStamp="20170805T175201+0100" uID="g149-2" Type="Goal"
Period="SecondHalf" Time="80" Sec="58" PlayerRef="p54782" Min="79"
EventNumber="2802" EventID="1632402633">
-<PlayerLineUp>
-<MatchPlayer PlayerRef="p84182" Status="Start" ShirtNumber="16"
Position="Goalkeeper">
<Stat Type="leftside_pass">7</Stat>
<Stat Type="accurate_keeper_sweeper">1</Stat>
<Stat Type="accurate_pass">30</Stat>
<Stat Type="rightside_pass">11</Stat>
<Stat Type="attempts_conceded_ibox">3</Stat>
<Stat Type="touches">44</Stat>
<Stat Type="total_fwd_zone_pass">2</Stat>
<Stat Type="keeper_pick_up">6</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p116406" Status="Start" ShirtNumber="5"
Position="Defender">
<Stat Type="duel_lost">2</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">34</Stat>
<Stat Type="att_rf_total">2</Stat>
<Stat Type="att_bx_right">1</Stat>
<Stat Type="accurate_pass">69</Stat>
<Stat Type="att_miss_left">1</Stat>
<Stat Type="total_final_third_passes">2</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p15780" Status="Start" ShirtNumber="32"
Position="Defender">
<Stat Type="total_through_ball">1</Stat>
<Stat Type="duel_lost">4</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">46</Stat>
<Stat Type="dispossessed">1</Stat>
<Stat Type="accurate_cross">2</Stat>
<Stat Type="att_rf_total">1</Stat>
</MatchPlayer>


I would like to get the Id of the player ("PlayerRef"), his "ShirtNumber", his "Position", the "Type of the statistic" and the "Statistic" itself.



For now, what I have done is close to the output expected, but I still got an error that I can't fix.
Here my python code :



import os
from xml.etree import ElementTree

file_name="C:/Users/Hp/Desktop/BYG/PSG-Amiens.xml"
full_file=os.path.abspath(os.path.join('BYG',file_name))
dom=ElementTree.parse(full_file)

Stats=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer/Stat')


for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))


When I run this code, it compiles all the type of statistics and the statistics of every players for just one player when it should be just the type of statistics of the player concerned and his statistics, not the one from all others players.



To be more clear, For the player 1 I should get just the ID, the ShirtNumber,
the Position, All the type of Statistics and the statistics for the player 1.



But instead I get his ID, ShirtNumber,Position and All the type of Statistics and the statistics present in my xml file.



How could I fix that?



I hope I have been clear enough, don't hesitate to ask me more precisions if I haven't been clear enough



Thanks in advance










share|improve this question













I'm trying to create a database using python on my xml file. I'm closed to the output I wish.



First, here is my Xml :



<?xml version="1.0" encoding="UTF-8"?>
-<SoccerFeed TimeStamp="20180518T155346+0100">
-<SoccerDocument uID="f920535" detail_id="1" Type="Result">
+<Competition uID="c24">
-<MatchData>
+<MatchInfo TimeStamp="20170805T180614+0100" Period="FullTime"
MatchType="Regular">
-<MatchOfficial uID="o41564">
+<OfficialData>
+<OfficialName>
</MatchOfficial>
+<AssistantOfficials>
<Stat Type="match_time">95</Stat>
<Stat Type="first_half_start">20170805T161515+0100</Stat>
<Stat Type="first_half_time">46</Stat>
<Stat Type="first_half_stop">20170805T170023+0100</Stat>
<Stat Type="second_half_start">20170805T171702+0100</Stat>
<Stat Type="second_half_time">50</Stat>
<Stat Type="second_half_stop">20170805T180614+0100</Stat>
-<TeamData TeamRef="t149" Side="Home" Score="2">
-<Goal TimeStamp="20170805T165633+0100" uID="g149-1" Type="Goal"
Period="FirstHalf" Time="42" Sec="18" PlayerRef="p40720" Min="41"
EventNumber="1421" EventID="1618948311">
<Assist PlayerRef="p15780">p15780</Assist>
</Goal>
+<Goal TimeStamp="20170805T175201+0100" uID="g149-2" Type="Goal"
Period="SecondHalf" Time="80" Sec="58" PlayerRef="p54782" Min="79"
EventNumber="2802" EventID="1632402633">
-<PlayerLineUp>
-<MatchPlayer PlayerRef="p84182" Status="Start" ShirtNumber="16"
Position="Goalkeeper">
<Stat Type="leftside_pass">7</Stat>
<Stat Type="accurate_keeper_sweeper">1</Stat>
<Stat Type="accurate_pass">30</Stat>
<Stat Type="rightside_pass">11</Stat>
<Stat Type="attempts_conceded_ibox">3</Stat>
<Stat Type="touches">44</Stat>
<Stat Type="total_fwd_zone_pass">2</Stat>
<Stat Type="keeper_pick_up">6</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p116406" Status="Start" ShirtNumber="5"
Position="Defender">
<Stat Type="duel_lost">2</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">34</Stat>
<Stat Type="att_rf_total">2</Stat>
<Stat Type="att_bx_right">1</Stat>
<Stat Type="accurate_pass">69</Stat>
<Stat Type="att_miss_left">1</Stat>
<Stat Type="total_final_third_passes">2</Stat>
</MatchPlayer>
-<MatchPlayer PlayerRef="p15780" Status="Start" ShirtNumber="32"
Position="Defender">
<Stat Type="total_through_ball">1</Stat>
<Stat Type="duel_lost">4</Stat>
<Stat Type="blocked_scoring_att">1</Stat>
<Stat Type="leftside_pass">46</Stat>
<Stat Type="dispossessed">1</Stat>
<Stat Type="accurate_cross">2</Stat>
<Stat Type="att_rf_total">1</Stat>
</MatchPlayer>


I would like to get the Id of the player ("PlayerRef"), his "ShirtNumber", his "Position", the "Type of the statistic" and the "Statistic" itself.



For now, what I have done is close to the output expected, but I still got an error that I can't fix.
Here my python code :



import os
from xml.etree import ElementTree

file_name="C:/Users/Hp/Desktop/BYG/PSG-Amiens.xml"
full_file=os.path.abspath(os.path.join('BYG',file_name))
dom=ElementTree.parse(full_file)

Stats=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineUp/MatchPlayer/Stat')


for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))


When I run this code, it compiles all the type of statistics and the statistics of every players for just one player when it should be just the type of statistics of the player concerned and his statistics, not the one from all others players.



To be more clear, For the player 1 I should get just the ID, the ShirtNumber,
the Position, All the type of Statistics and the statistics for the player 1.



But instead I get his ID, ShirtNumber,Position and All the type of Statistics and the statistics present in my xml file.



How could I fix that?



I hope I have been clear enough, don't hesitate to ask me more precisions if I haven't been clear enough



Thanks in advance







python xml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 10:25









Jordi

63




63












  • It looks like you are iterating through all 'MatchPlayer/Stat' elements. You should narrow your search to only get the stats of the player you are working with.
    – boonwj
    Nov 11 at 11:02










  • Unrelated, but do those + and - really appear in your XML?
    – usr2564301
    Nov 11 at 12:02










  • @usr2564301 It appears on my XML interpreter, but not on a url file
    – Jordi
    Nov 11 at 14:23


















  • It looks like you are iterating through all 'MatchPlayer/Stat' elements. You should narrow your search to only get the stats of the player you are working with.
    – boonwj
    Nov 11 at 11:02










  • Unrelated, but do those + and - really appear in your XML?
    – usr2564301
    Nov 11 at 12:02










  • @usr2564301 It appears on my XML interpreter, but not on a url file
    – Jordi
    Nov 11 at 14:23
















It looks like you are iterating through all 'MatchPlayer/Stat' elements. You should narrow your search to only get the stats of the player you are working with.
– boonwj
Nov 11 at 11:02




It looks like you are iterating through all 'MatchPlayer/Stat' elements. You should narrow your search to only get the stats of the player you are working with.
– boonwj
Nov 11 at 11:02












Unrelated, but do those + and - really appear in your XML?
– usr2564301
Nov 11 at 12:02




Unrelated, but do those + and - really appear in your XML?
– usr2564301
Nov 11 at 12:02












@usr2564301 It appears on my XML interpreter, but not on a url file
– Jordi
Nov 11 at 14:23




@usr2564301 It appears on my XML interpreter, but not on a url file
– Jordi
Nov 11 at 14:23












1 Answer
1






active

oldest

votes

















up vote
0
down vote













You should look up the specific individual player statistics while iterating through the player stats.



for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat'.format(ID))

for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))





share|improve this answer





















  • thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
    – Jordi
    Nov 11 at 14:48











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247810%2fxml-python-parsing-for-creating-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You should look up the specific individual player statistics while iterating through the player stats.



for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat'.format(ID))

for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))





share|improve this answer





















  • thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
    – Jordi
    Nov 11 at 14:48















up vote
0
down vote













You should look up the specific individual player statistics while iterating through the player stats.



for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat'.format(ID))

for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))





share|improve this answer





















  • thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
    – Jordi
    Nov 11 at 14:48













up vote
0
down vote










up vote
0
down vote









You should look up the specific individual player statistics while iterating through the player stats.



for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat'.format(ID))

for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))





share|improve this answer












You should look up the specific individual player statistics while iterating through the player stats.



for s in Stats:
ID=s.get('PlayerRef')
Position=s.get('Position')
Shirt=s.get('ShirtNumber')
Type=dom.findall('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat'.format(ID))

for t in Type:
Types=t.get('Type')
Reponse=t.text
print(' * {} [{}] {} - {} {}'.format(ID,Position,Shirt,Types,Reponse))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 11:13









boonwj

2189




2189












  • thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
    – Jordi
    Nov 11 at 14:48


















  • thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
    – Jordi
    Nov 11 at 14:48
















thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
– Jordi
Nov 11 at 14:48




thanks for the answer, but with running your code I get a KeyError: KeyError: ('SoccerDocument/MatchData/TeamData/PlayerLineU/MatchPlayer[@PlayerRef={0}]/Stat', None) And some others errors: File "C:Program Files (x86)Python37-32libxmletreeElementTree.py", line 697, in findall return self._root.findall(path, namespaces) File "<string>", line None SyntaxError: invalid predicate
– Jordi
Nov 11 at 14:48


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247810%2fxml-python-parsing-for-creating-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation