PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → XMLREad vs Node
XMLREad vs Node
Iniciado por guest, 13,abr. 2016 11:50 - 6 respuestas
Publicado el 13,abril 2016 - 11:50
Hello everybody,
here I am with a very strange issue processing an XML file.

I have a WD app which has a process reading XML files to extract some data related to products. So this process was working fine by using this code:
nSUP_GLN = XMLRead("MyXML","/catalogueItemNotificationMessage/transaction/documentCommand/catalogueItemNotification/catalogueItem/tradeItem/informationProviderOfTradeItem/gln")

Now the provider of the XML files has changed the strucure of the XML files and now this line is currently returning zero instead of the value in the attibute. So after investigating and struggling to get it working again I had to change my code for this one:
xNode = xmlFile.catalogueItemNotificationMessage.transaction.documentCommand.catalogueItemNotification.catalogueItem.tradeItem.informationProviderOfTradeItem.gln
nSUP_GLN = xNode..Text
and the right value is returned of course. But that means I need to change all the code in my program.

Can someone explain why? the path is actually the same in both coding formats but the first one says the path is wrong and returns zero and the second one is working fine.
Really do not understand the difference.

Any help or comment is welcome.

Thanks in advance.

Regards,

Victoria
Publicado el 14,abril 2016 - 14:08
Hi

Could you give more detail about this with a full layout of your xmlFile struct and
sample data, is it embedded or dynamically created...

Regs

King
Publicado el 14,abril 2016 - 15:39
Hi King,
thanks for your reply.

The XML file is created by another company and they place the files in our FTP so we then read them and process them.

This is an overview of one of the paths I am reading as in the code example:
http://screencast.com/t/yJ3ZUYiKxSt
Maybe you can see something I do not :-).

Thanks again.

Regards,

Victoria
Publicado el 14,abril 2016 - 23:11
Victoria


IF the .xsd changed so does .xml, you have to change code to ensure node/element name
to be read in ... dot notation.

All I can show you is below:

cMyDoc is xmlDocument
cMyDoc.description = fLoadText("c:\xsd\ooks.xsd")
cMyDoc.person.lastname = "Moore"
cMyDoc.person.firstname = "Vince"
cMyDoc.person.dob = "19710211"
cMyDoc.person.email[1] = "vince.moore@mydomain.com"
cMyDoc.person.email[2] = "vince.moore@otherdomain.com"

info(cMyDoc.person.email[1] )
// will display vince.moore@mydomain.com

//based on Definition in person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="lastname" type="xsd:string"/>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="dob" type="xsd:date"/>
<xsd:element name="email" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
// end person.xsd

Try read dynamically to read in element/node name,
even if the provider changed XSD structure, you could locate data accordingly.

Don't hardcode/embed in your wd project or you have to change all codes
in your project

HTH

King
Publicado el 20,abril 2016 - 14:43
Hi King,
thanks for your response.
The problem is that the Provider of the XML never provided us with the XSD.
Now for the new version of the XML files they provide me with 70 different XSD files so now I am trying to figure out what should I do with them since I thought there was only one XSD file to describe the elements in an XML document.

Regards,

Victoria
Publicado el 21,abril 2016 - 04:41
Vic

I'm afraid that you have to live with it for writing your own xml parser to overcome such.

I wonder if people move to JSON, have a look the link as below:

http://27130.foren.mysnip.de/read.php…

not much help, sorry :((

King
Publicado el 21,abril 2016 - 04:48
Also have a look a link as below for dynamic creation to import XML data into
hyperfile with any creation of analysis .wdd.

http://27130.foren.mysnip.de/read.php…

Of course, bug is possible since I wrote it 6 yrs ago.

HTH

Cheers

King