0
votes

I have a PHP client that has to query datasets from a service that uses .NET. So, I was trying to make a query by passing a POST field called 'query'. Inside this variable, I have a string version of XML document. What's happening now is that whenever I passed this 'query' to the server, it will throw an exception at me 'Data at the root level is invalid.' and point to the last line of my XML document.

Any tips?

Here's the XML

<?xml version="1.0" encoding="utf-8"?>
<Predicate>
  <ComparisonPredicate name="like" isEnabled="True" id="" DistinctIndividualQueries="False">
    <FacetOperand reference="TriggeredAlerts.Alert.Name"/>
    <Comparison operation="like"/>
    <ValueOperand type="System.String" value="Sample"/>
  </ComparisonPredicate>
</Predicate>

Here's the var_dump()

string(335) "<?xml version="1.0" encoding="utf-8"?>
<Predicate>
  <ComparisonPredicate name="like" isEnabled="True" id="" DistinctIndividualQueries="False">
    <FacetOperand reference="TriggeredAlerts.Alert.Name"/>
    <Comparison operation="like"/>
    <ValueOperand type="System.String" value="TestAlert"/>
  </ComparisonPredicate>
</Predicate>
"
1
Smells like a missing or invalid closing tag in the root element of the document to me... Can you post the XML document you are trying to parse? - DaveRandom
@DaveRandom Added a sample XML - Ye Myat Min
I can't see anything wrong with the document, can you show a var_dump() of the variable that contains your XML? - DaveRandom
@DaveRandom There you go. I'm posting this to the .NET web service. - Ye Myat Min
Maybe this will help? Your string may contain an UTF-8 BOM. - DaveRandom

1 Answers

0
votes

I just figured it out and the solution was to use fsocksopen instead of curl. I do not have an accurate answer for that but when I was using curl, it added some extra stuffs to my content; my content length was significantly longer than it is actually supposed to be.