load XML from variable, not File - c++

I'm trying to parse XML data stored in a variable, not a file. The reason for this is that program x replies to program y in XML, so it would seem to be best to directly parse the XML from the variable.
So far I have tried to do this in TinyXML, but I don't see an interface to load from a variable.
It's basically the opposite of TinyXML: Save document to char * or string, instead of saving to char, I want to load from char(or string)
For example instead of the following:
TiXmlDocument doc( "demo.xml" );
doc.LoadFile();
something like
doc.LoadVar(char*)
I also checked out RapidXML, but I also can't seem to find documentation to load from a variable.
Thanks

You can use TiXmlDocument::Parse. See tinyxml documentation for more details.

If you already have the document in a string why not simply call the TiXmlDocument::Parse method and be done?

Related

ColdFusion CF2021 xmlParse(file) returning wddx encoded object

UPDATE: After doing some more poking around, it looks as though the problem has to do with where CF is looking for the DTD file referenced in the XML.
We have the DTDs, but it looks as though CF isn't finding them, so it isn't sure how to parse the XML according to the DTD. I determined this by having it parse XML without any DTD, and it worked as expected and as I wanted - returning a parsed xmlDoc, not a string.
Is there some way of setting the default directory for where CF should look for the DTD specified in the XML?
We're running CF2021, and xmlParse(file), which should return a parsed XML object is instead returning the file contents as a string, inside a wddx encoded object. We have just migrated from a CF2018 server running on a remote hosting service to CF2021 running on an AWS box.
In order to return the XML object we need, I need to run xmlParse on the file, then wddx2cfml on the object, then xmlParse again on the string.
Is there a reason why xmlParse, which should return a parsed XML object, is instead behaving this way?
We pass the system file location to the method. Call it docPath, and it'd look something like g:\appName\xmlFiles\20230125.xml
Then we have, in cfscript:
doc = xmlParse(docPath);
When I dump that to a file, I get what I described above. When I change it to the following, I get what want:
docFile = xmlParse(docPath); cfwddx(action="wddx2cfml", input="#docFile#", output="xmlString"); xmlDoc = xmlParse(xmlString);
But I don't understand why this is necessary, and I'm concerned about having to change it everywhere in the code that we use xmlParse. For the record, this also occurs in tagged CF as well as cfscript, so it's not that.
Putting the dtd files in CF's WEB-INF folder solved the problem. CF was able to match the DTD with the DOCTYPE and properly parse the XML.

Apache Beam/Dataflow- passing file path to ReadFromText

I have a use case where I want to read the filename from a metadata table, I have written a pipeline function to read the metadata table, but I am not sure how can I pass this information to ReadFromText as it only takes string as input, Is it possible to assign this value to ReadFromText(). Please suggest some workarounds or ideas how to achieve this, Thanks
code: pipeline | 'Read from a File' >> ReadFromText(I want to pass the file path here?,
skip_header_lines=1)
Note: There will be various folders and files in storage, files are in csv format, but in my use case I can't directly pass the storage location or filename to file path in ReadFromText. I want to read it from metadata and pass the value. Hope I am clear, Thanks
I don't understand why you need to read the metadata. If you want to read all the files inside a folder, you can just provide a blob. This solution working in python, not sure about java.
p|readfromtext("./folder/*.csv")
"*" is the blob here, which allows pipeline to read all the patterns matching .csv. You can also add something at the starting.
What you want is textio.ReadAllFromText which reads from a PCollection instead of taking a string directly.

Deserialise CDATA values

As part of our coding, we need to fetch values from a string which is capsulated in CDATA function.
Unfortunately Datapower doesnot recognise CDATA as a valid XSL function.
Is there anyway in XSL Programming, i can deserialise the string and take the needed values.
Used DP:PARSE function in Datapower and thus able to deserialise it. Thanks.

getting XML data from Xerces (c++)

I am a latecomer to XML - have to parse an XML file. Our company is using xerces already so I managed to cobble together a sample app (SAX) that displays all the data in a file. However, after parsing is complete I was expecting to be able to call the parser or some other entity that had an internal representation of the file and iterate through the fields/data.
Basically I want to be able to hand it some key or other string(s) and get back strings or collections of key/value pairs. I do not see that. It seems pretty obvious to me that that is a good thing to do. Am I missing something?
Is the DOM parsing what I want, or does that fall short too?
Xerces provides both SAX and DOM processing. SAX parsing doesn't construct a model, so once parsing is finished there is nothing to examine or iterate through. DOM processing produces a tree-structured model which gives you what you want.
Check out the beginner's sample in this page
YoLinux Tutorial on Parsing XML
If you use the XercesDOMParser, there is still no way to request a specific key value pair after the document is parsed. I ran into the same problem recently, and while iterating through the DOM tree I stored all the key value pairs in an STL map. Then you can request key value pairs from the map later in the program.

How do I view the contents of an IXMLDOMElementPtr when building an XML file?

I'm using IXMLDOM in MSXML 6 to build an XML file in a C++ MFC application. Is there a way to see the contents of the xml document while it is in memory?
For example, an XPATH query is failing about halfway through creating the file. How would I view the entire contents of the xml doc?
Thanks!
IXMLDOMElement derives from IXMLDOMNode, and IXMLDOMNode has an xml property that you can use to get the textual representation of the XML in memory.
IXMLDOMElementPtr spElement = ...;
_bstr_t xmlContents = spElement->xml();
If you're looking for a way to see the contents of the XML in the debugger without changing existing code to add this call, that may be possible, but I'm not exactly sure where to look.