i have an xml document that i need to parse in the most efficient way, the syntax of the document is like this -
<?xml version="1.0" ?>
-
- <frameNumber4>
-
- <v0>
-
<X>0.148778095841</X>
-
<Y>-0.987688362598</Y>
-
<Z>-0.0483409352601</Z>
-
</v0>
-
- <v1>
-
<X>0.126558214426</X>
-
<Y>-0.987688362598</Y>
-
<Z>-0.0919499248266</Z>
-
</v1>
-
etc....
so i need to parse this as in im accessing <v0><X>, is this possible?
i know i can do it in a manner where i take the v0 and parse it again to get the X, but i was wondering if there was a more efficient way of direct access to a 2nd level member
on the other hand, i know this should be a really dumb question, but how do i get the value of the element, and not the whole xml, all i know of is the method toxml which gives me the whole <Z>-0.0919499248266 </Z>
and here's the code im using so far in case it should come in handy :) -
from xml.dom.minidom import parse
-
dom = parse('D:\\newCache\\pSphere2-004.xml')
-
for node in dom.getElementsByTagName('v0'):
-
print node.toxml()
-
-
3 2028 bvdet 2,851
Recognized Expert Moderator Specialist
Following are a couple of ways to get the data in a usable form: - from xml.dom import minidom
-
-
doc = minidom.parse('your.xml')
-
-
def get_XYZ(elem):
-
x = float(elem.getElementsByTagName("X")[0].firstChild.data)
-
y = float(elem.getElementsByTagName("Y")[0].firstChild.data)
-
z = float(elem.getElementsByTagName("Z")[0].firstChild.data)
-
return x,y,z
-
-
# Get document element matching a given tag name
-
print get_XYZ(doc.getElementsByTagName("v0")[0])
-
print get_XYZ(doc.getElementsByTagName("v1")[0])
-
-
def get_XYZ1(name):
-
output = []
-
for node in doc.getElementsByTagName(name):
-
t = node.firstChild.nextSibling
-
while t:
-
s = repr(t).strip()
-
if not '\\n' in s:
-
output.append([name, str(t.localName), float(t.firstChild.data)])
-
t = t.nextSibling
-
return output
-
-
print get_XYZ1('v0')
-
print get_XYZ1('v1')
Output: - >>> (0.14877809584099999, -0.98768836259799997, -0.048340935260099999)
-
(0.12655821442599999, -0.98768836259799997, -0.091949924826599999)
-
[['v0', 'X', 0.14877809584099999], ['v0', 'Y', -0.98768836259799997], ['v0', 'Z', -0.048340935260099999]]
-
[['v1', 'X', 0.12655821442599999], ['v1', 'Y', -0.98768836259799997], ['v1', 'Z', -0.091949924826599999]]
-
>>>
seriously thank you! i cant thank you enough,
but if i may ask one more thing, i really looked around the internet for good documentation, noone even mentioned the ".data", what source do you recommend??
bvdet 2,851
Recognized Expert Moderator Specialist
seriously thank you! i cant thank you enough,
but if i may ask one more thing, i really looked around the internet for good documentation, no one even mentioned the ".data", what source do you recommend??
I have found a few simple parsing examples on the internet, and I use Python Essential Reference and Python documentation for reference, which are both very basic. The data attribute is only available for text nodes. I am trying to learn XML parsing also. It helps to know XML. There are many online resources on XML, DOM and SAX.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Cedric Baelemans |
last post by:
Hi,
I try to store a two-dimentional array in a session variable. When I do the
same with a one-dimentional array, it works fine, but with a two-dimentional
array it fails. Is this not possible? Is there something special I have to
take into account?
Any help is welcome
Cedric
|
by: Al |
last post by:
I'd like to declare (in a Matrix class) a two-dimentional array with
user-defined coordinates. The constructor is:
Matrix(int c, int l): col(c), lin(l), a(new float) {}
the compiler says 'lin' should be a constant, but I want it to be
defined from the user, so what should I do? and how must 'a' be
declared??
help me please
|
by: rkmoray |
last post by:
I have created a Multi Dimentional array, but having problems filling
it.
int mCount=0;
mCount=ds.Tables.Rows.Count;
string arrayppsa = new string ;
DataTable myDataTable=ds.Tables;
foreach(DataRow myDataRow in myDataTable.Rows) {
|
by: Max M. Power |
last post by:
I'm getting an InvalidOperationException calling Invoke with a method
parameter object array that contains a two dimentional string array. More
stack trace output below:
// Create two dimentional array.
System::String* tda = new System::String*;
tda = "lastName";
tda = "Power";
tda = "firstName";
tda = "Max";
|
by: ranjmis |
last post by:
Hi all,
Below is the code wherein I am initializing double dimentional array
inside main with string literals.
Now I want to display the strings using a function call to which I just
want to pass the array as argument with no other info like number of
strings.
Is there a way to achieve that?
| |
by: Icarus27 |
last post by:
Hello,
I am making a program that runs off of a two dimentional array but I have made it into a game called MouseBot. I am trying to make the game so that you can move the mouse until you get the cheese. It has four different difficulty levels and you have obsticles in your way (the amount depends on the difficulty level).
The problem I am having is that when I move the 'M' (mousebot) into the array space that the cheese ('C') is in it...
|
by: cmdolcet69 |
last post by:
I can the following error message "value of type byte cannot be
converted to 1-dimentional array of byte" when i execute this line of
code:
moRS232.Write(Packet(i))
it underline the packet(i)
this is my declared array of byte size (6)
|
by: Srinu |
last post by:
Hi All,
We know the following facts,
1. A two dimentional arrays in C is stored similar to a single
dimentional array.
2. * is the dereference operator that gives value at address denoted
by the operand to this operator. i.e *p is the value at address given
by p.
3. In case of two dimentional array a, a+1 refers to the second
|
by: neovantage |
last post by:
Hey all,
I need to sort 2 dimentional array.
My data is in this form
arrayName = decimal value say 1
arrayName = name say abc
arrayName = decimal value say 2
arrayName = name say def
arrayName = decimal value say 3
arrayName = name say xyz
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |