473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

only a simple xml reader <tag:id>value </tag:id>

H!,

Is it possible to get a <tag:id>value </tag:id> value ?

When I do this:
-----------------------------------------------------
theXML = """<?xml version="1.0"?>
<title>The Fascist Menace</title>
"""
import xml.dom.minidom as dom
doc = dom.parseString (theXML)
print doc.getElements ByTagName('titl e')[0].toxml()

I get : <title>The Fascist Menace</title> thats oke for me
-----------------------------------------------------

But the xmlfile I must read have other tags:
theXML = """<?xml version="1.0"?>
<title:id>The Fascist Menace</title:id>
<title:name>b la la etc</title:name>
"""

how to get that values ?
I try things like:
print doc.getElements ByTagName('titl e:id')[0].toxml() <--error

Thanks,
GC-Martijn

Feb 8 '06 #1
4 1894

ma*****@gamecre ators.nl wrote:
H!,

Is it possible to get a <tag:id>value </tag:id> value ?

When I do this:
-----------------------------------------------------
theXML = """<?xml version="1.0"?>
<title>The Fascist Menace</title>
"""
import xml.dom.minidom as dom
doc = dom.parseString (theXML)
print doc.getElements ByTagName('titl e')[0].toxml()

I get : <title>The Fascist Menace</title> thats oke for me
-----------------------------------------------------

But the xmlfile I must read have other tags:
theXML = """<?xml version="1.0"?>
<title:id>The Fascist Menace</title:id>
<title:name>b la la etc</title:name>
"""

how to get that values ?
I try things like:
print doc.getElements ByTagName('titl e:id')[0].toxml() <--error


Addressing your general question, unfortunately you're a bit stuck.
Minidom is rather confused about whether or not it's a namespace aware
library. Addressing your specific example, I strongly advise you not
to use documents that are not well-formed according to Namespaces 1.0.
Your second example is a well-formed XML 1.0 external parsed entity,
but not a well-formed XML 1.0 document entity, because it has multiple
elements at document level. It's also not well-formed according to
XMLNS 1.0 unless you declare the "title" prefix. You will not be able
to use a non XMLNS 1.0 document with most XML technologies, including
XSLT, WXS, RELAX NG, etc.

If you have indeed declared a namespace and are just giving us a very
bad example, use:

print doc.getElements ByTagNameNS(tit le_namespace, 'id')

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Feb 8 '06 #2
I'm newbie with that xml stuff.

The only thing I must read is the response I get from a EPP server.
A response like this:

<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns=" http://www.eurid.eu/xml/epp/epp-1.0"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:contact=" http://www.eurid.eu/xml/epp/contact-1.0"
xmlns:domain="h ttp://www.eurid.eu/xml/epp/domain-1.0"
xmlns:eurid="ht tp://www.eurid.eu/xml/epp/eurid-1.0"
xmlns:nsgroup=" http://www.eurid.eu/xml/epp/nsgroup-1.0"
xsi:schemaLocat ion="http://www.eurid.eu/xml/epp/epp-1.0 epp-1.0.xsd
http://www.eurid.eu/xml/epp/contact-1.0 contact-1.0.xsd
http://www.eurid.eu/xml/epp/domain-1.0 domain-1.0.xsd
http://www.eurid.eu/xml/epp/eurid-1.0 eurid-1.0.xsd
http://www.eurid.eu/xml/epp/nsgroup-1.0 nsgroup-1.0.xsd">
<response>
<result code="1500">
<msg>Command completed successfully; ending session</msg>
</result>
<resData>
<domain:appData >
<domain:name> c-and-a.eu</domain:name>
<domain:referen ce> c-and-a_1</domain:referenc e>
<domain:code>25 65100006029999</domain:code>
<domain:crDate> 2005-11-08T14:51:08.929 Z</domain:crDate>
</domain:appData>
</resData>
<extension>
<eurid:ext>
<eurid:result >
<eurid:msg>OK </dnsbe:msg>
</eurid:result>
</eurid:ext>
</extension>
<trID>
<clTRID>clientr ef-12310026</clTRID>
<svTRID>eurid-1589</svTRID>
</trID>
</response>
</epp>
----------------
//<result code="1500">
//<msg>Command completed successfully; ending session</msg>

what is the official/best way to handle/parse such xml response ?

Thats maybe a better question

Feb 8 '06 #3
ma*****@gamecre ators.nl wrote:
I'm newbie with that xml stuff.

The only thing I must read is the response I get from a EPP server.
A response like this:

<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns=" http://www.eurid.eu/xml/epp/epp-1.0"
xmlns:xsi="htt p://www.w3.org/2001/XMLSchema-instance"
xmlns:contact= "http://www.eurid.eu/xml/epp/contact-1.0"
xmlns:domain=" http://www.eurid.eu/xml/epp/domain-1.0"
xmlns:eurid="h ttp://www.eurid.eu/xml/epp/eurid-1.0"
xmlns:nsgroup= "http://www.eurid.eu/xml/epp/nsgroup-1.0"
xsi:schemaLoca tion="http://www.eurid.eu/xml/epp/epp-1.0 epp-1.0.xsd
http://www.eurid.eu/xml/epp/contact-1.0 contact-1.0.xsd
http://www.eurid.eu/xml/epp/domain-1.0 domain-1.0.xsd
http://www.eurid.eu/xml/epp/eurid-1.0 eurid-1.0.xsd
http://www.eurid.eu/xml/epp/nsgroup-1.0 nsgroup-1.0.xsd">
<response>
<result code="1500">
<msg>Command completed successfully; ending session</msg>
</result>
<resData>
<domain:appDat a>
<domain:name >c-and-a.eu</domain:name>
<domain:refere nce> c-and-a_1</domain:referenc e>
<domain:code>2 565100006029999 </domain:code>
<domain:crDate >2005-11-08T14:51:08.929 Z</domain:crDate>
</domain:appData>
</resData>
<extension>
<eurid:ext>
<eurid:resul t>
<eurid:msg>O K</dnsbe:msg>
</eurid:result>
</eurid:ext>
</extension>
<trID>
<clTRID>client ref-12310026</clTRID>
<svTRID>euri d-1589</svTRID>
</trID>
</response>
</epp>
----------------
//<result code="1500">
//<msg>Command completed successfully; ending session</msg>

what is the official/best way to handle/parse such xml response ?

Thats maybe a better question

try something like this:

import xml.dom.minidom as dom
doc = dom.parseString ("""<?xml version="1.0"?>
<title>The Fascist Menace</title>""")
print doc.getElements ByTagName('titl e')[0].childNodes[0].data

Feb 9 '06 #4
ma*****@gamecre ators.nl wrote:
The only thing I must read is the response I get from a EPP server.
A response like this:

<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns=" http://www.eurid.eu/xml/epp/epp-1.0"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:contact=" http://www.eurid.eu/xml/epp/contact-1.0"
xmlns:domain="h ttp://www.eurid.eu/xml/epp/domain-1.0"
xmlns:eurid="ht tp://www.eurid.eu/xml/epp/eurid-1.0"
xmlns:nsgroup=" http://www.eurid.eu/xml/epp/nsgroup-1.0"
xsi:schemaLocat ion="http://www.eurid.eu/xml/epp/epp-1.0 epp-1.0.xsd
http://www.eurid.eu/xml/epp/contact-1.0 contact-1.0.xsd
http://www.eurid.eu/xml/epp/domain-1.0 domain-1.0.xsd
http://www.eurid.eu/xml/epp/eurid-1.0 eurid-1.0.xsd
http://www.eurid.eu/xml/epp/nsgroup-1.0 nsgroup-1.0.xsd">
<response>
<result code="1500">
<msg>Command completed successfully; ending session</msg>
</result>
<resData>
<domain:appData >
<domain:name> c-and-a.eu</domain:name>
<domain:referen ce> c-and-a_1</domain:referenc e>
<domain:code>25 65100006029999</domain:code>
<domain:crDate> 2005-11-08T14:51:08.929 Z</domain:crDate>
</domain:appData>
</resData>
<!-- SNIP -->
</response>
</epp>


So to get the msg, you can do:

print doc.getElements ByTagName('msg' )[0].toxml()

But to get the domain:name you have to use the declared namespace:

print
doc.getElements ByTagNameNS('ht tp://www.eurid.eu/xml/epp/domain-1.0',
'name')[0].toxml()

Or you can make life a bit easier with Amara [1]:

import amara
doc = amara.parse(the XML)
print doc.response.re sult.msg #to get the text content
print doc.response.re sult.msg.xml() #to get the XML source for that
element
print doc.response.re sData.appData.n ame
print doc.response.re sData.appData.n ame.xml()

[1] http://uche.ogbuji.net/tech/4Suite/amara/

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

Feb 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13155
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like this, with a flush left margin:
6
2834
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down and adjust to the newly added items like it does in iE. It just occured to me that i dont really have to use a span, and a html <hr> tag could do the trick -I will go try. But aside from that could some one explain why this occurs? And will I get...
15
2251
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
1
3109
by: Rafaela K. Azinhal | last post by:
Hi, I'm a newbie and have a question: I have following PivotTable object in a HTML page <html> <body> <object class='ptdrillthrough' classid="clsid:0002E552-0000-0000-C000-000000000046" id="pt">
4
1566
by: Neil Zanella | last post by:
Hello, I would like to know what the difference is among the constructs <%= %> for evaluating an expression and displaying the evaluated result on the page and <%# %>. In particular I would like to know why the <%# %> construct is necessary in locations where the other <%= %> does not do. It seems to me that there is no equivalent of the <%# %> construct in PHP, thus I thought I would post to clarify. Is this an ASP.NET specific...
3
2941
by: ajaspersonal | last post by:
"i want to change font_style (hyper link<a href...>text</a>) normal to italics.when load a page" this is my problem but that label included in one 'USERCONTROL' This user controls may condain 4 link (<a href...>page1.aspx</a <br <a href ....>page2</aetc..). that will redirect another page ex:(page1.aspx).
10
14173
by: neverquit | last post by:
hi , Iam Nagesh,Begineer in using Ajax,well i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag iam able to get the response in the <div> tag in mozilla (im takingthe HTML response), <script> function confirm() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null)
7
4674
by: Max2006 | last post by:
Hi, When I use this tag: <asp:lable . Visible='<%# IsEditable %>' I have to do DataBind so the binding takes place. I am trying to use the following notation to do the similar thing without forced to call DataBind method:
5
1814
Claus Mygind
by: Claus Mygind | last post by:
I want to dynamically add a hidden <div> </div> to a document when loading my page. It is kind of a generic scratch pad into which I can load messages and data I may want to display to the user. I want to do it this way so I can place it in my base .js file for inclusion in all apps I write without having to reinvent the wheel each time. My problem is this; the <body> tag does not seem to pass the "id" value but rather the name of the...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.