Announcements
When trying to read xmldata over url I will get xml but xmldocument.loadxml() reads only first line from response.
what is wrong?
code:
static void Job303(Args _args)
{
COM objXHTTP;
xml xmlDocumentOut;
url xmlUrl;
str xmlError;
str xmlDocumentResponse;
//#define.xmlhttp('MSXML2.XMLHTTP')
#define.serverXmlHttp('MSXML2.ServerXMLHTTP')
#define.xmlResolve(3000)
#define.xmlConnect(3000)
#define.xmlSend(3000)
#define.xmlReceive(3000)
interopPermission interopPermission;
int xxx;
XMLNode rootNode, bodyNode,bodyNode1,AttNode;
XMLNodeList bodyLines,childLine;
XMLElement xmlElement;
XMLNodeList _xmlNodelist;
XMLDocument XMLdoc = new XMLDocument();
str filename, nodeName,txtFile,strTxtRow;
str AttName;
int i,j,k;
boolean Valid;
;
xmlDocumentOut = ''; // Set your XML Doc
xmlUrl = 'mirpol.rzeszow.pl/.../itqty2022.xml'; // Set the URL
interopPermission = new InteropPermission(InteropKind::ComInterop);
InteropPermission.assert();
objXHTTP = new COM(#serverxmlHttp);
objXHTTP.settimeouts(#xmlResolve, #xmlConnect, #xmlSend, #xmlReceive);
objXHTTP.Open("POST", xmlUrl, False);
objXHTTP.setRequestHeader("Content-Type", "text/xml.");
objXHTTP.send(xmlDocumentOut);
xmlDocumentResponse = objXHTTP.responseText();
info(xmlDocumentResponse);
XMLDoc.loadxml(xmlDocumentResponse);
objXHTTP = null;
codeAccessPermission::revertAssert();
// XMLdoc.load(@"C:\temp\textIOtest.xml");
rootNode = xmldoc.documentElement();
nodeName = rootnode.baseName();
xmlElement = xmldoc.documentElement();
if(rootnode.hasChildNodes())
{
bodyLines = rootnode.childNodes();
}
}
removing ufff -s fixed half data, but something is still blocking
xmlDoc.load(xmlUrl); xmldoc will remain empty
Maybe someone gives you an advice if you tell us more about your problem than just "it's not working".
simplest solution is not working. not sure about HttpClient how to use it
You seem to be focusing on a wrong piece of code. If xmlDocumentResponse doesn't contain correct data, there is no point in trying to use it. The problem is in how you're getting the value for xmlDocumentResponse.
I don't know why you're using the COM object. I've never done and I would avoid it, even if it worked.
The simplest solution may be loading the document directly from a URL. Give it a try:
xmlDoc.load(xmlUrl);
Alternatively you could download the file with HttpClient or something.
any ideas how to fix?
All right, we've just found the problem. The root element can't be loaded, because there is no element at all. The document is empty.
visually ok. And well i tried another url aswell and same problem. Can't select any nodes I guess LoadXML takes only first line from variable. <?xml version="1.0" encoding="windows-1250"?> and that's it. Tried to take a substring, but no better results.
Then it can't be true that you "got only first line". Your code throws an exception before you manage to extract any data at all.
Does xmlDocumentResponse variable contain valid XML? I doesn't seem to be the case.
wrote xmlDocumentResponse out to a test file via textio and tried to load it as file using xmldocument.load() method and got same error, but if I save xml from browser manually then I can load it. I can't figure out what's wrong, but I guess some hidden characters perhaps?
André Arnaud de Cal...
294,190
Super User 2025 Season 1
Martin Dráb
232,968
Most Valuable Professional
nmaenpaa
101,158
Moderator